Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support C99 designed initializers. #236

Merged

Conversation

francoisferrand
Copy link
Contributor

Standard C89 and C++ require the elements of an initializer to appear in a fixed order, the same as the order of the elements in the array or structure being initialized.

In ISO C99 you can give the elements in any order, specifying the array indices or structure field names they apply to.
To specify an array index, write `[index] =' before the element value. For example,

 int a[6] = { [4] = 29, [2] = 15 };

Gcc also adds an extension to initialize a range of elements to the same value, by writing `[first ... last] = value'. For example,

 int widths[] = { [0 ... 9] = 1, [10 ... 99] = 2, [100] = 3 };

In a structure initializer, specify the name of a field to initialize with `.fieldname =' before the element value. For example,

 struct point { int x, y; };
 struct point p = { .y = yvalue, .x = xvalue };

@francoisferrand francoisferrand changed the title Designedinitializers Support C99 designed initializers. Jun 16, 2014
Standard C89 and C++ require the elements of an initializer to appear in a fixed order, the same as the order of the elements in the array or structure being initialized.

In ISO C99 you can give the elements in any order, specifying the array indices or structure field names they apply to.
To specify an array index, write `[index] =' before the element value. For example,

     int a[6] = { [4] = 29, [2] = 15 };

Gcc also adds an extension to initialize a range of elements to the same value, by writing `[first ... last] = value'. For example,

     int widths[] = { [0 ... 9] = 1, [10 ... 99] = 2, [100] = 3 };

In a structure initializer, specify the name of a field to initialize with `.fieldname =' before the element value. For example,

     struct point { int x, y; };
     struct point p = { .y = yvalue, .x = xvalue };
wenns added a commit that referenced this pull request Jul 8, 2014
Support C99 designed initializers.
@wenns wenns merged commit 20903a3 into SonarOpenCommunity:master Jul 8, 2014
@francoisferrand francoisferrand deleted the designedinitializers branch July 9, 2014 07:35
@guwirth
Copy link
Collaborator

guwirth commented Dec 31, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants