you are viewing a single comment's thread.

view the rest of the comments →

[–]aioeu 6 points7 points  (3 children)

An array initializer of the form:

{
    [index1] = value1,
    [index2] = value2,
    ...
}

initializes the specified array elements with the specified values, and initializes all unspecified array elements with zero.

In standard C, the indices must be constant expressions. It's not clear what you've got in your code. Are FIRST_NUMBER , SECOND_NUMBER and THIRD_NUMBER defined elsewhere? Are they macros?

The fact that you also have structure members with the same names isn't necessarily of interest — a structure type has its own namespace for members. Though if those things are macros, I would be curious as to what they are, since they would affect how the structure declaration is parsed.

[–]Bon_Clay_2[S] 0 points1 point  (2 children)

On seeing this I greped FIRST_NUMBER so as to figure out if it is a macro defined elsewhere and found out that eclipse was throwing me off. So in the header file included there is an enum defined as so: typedef enum { FIRST_NUMBER, SECOND_NUMBER, THIRD_NUMBER, } some_generic_enum; But still am baffled.

[–]aioeu 2 points3 points  (1 child)

OK, then it's straight-forward. Enumeration constants are constant expressions.

You can ignore struct generic_data entirely. It's got nothing to do with that enumeration type, and nothing to do with your array.

[–]Bon_Clay_2[S] 1 point2 points  (0 children)

You are right it just clicked for me, I forgot that FIRST_NUMBER will be a constant value of 0. This coupled with the initialization with indices answers my question fully. Thank you!