[cfe-dev] Designated initialization warns if struct members are not in declaration order
Sascha Wildner
swildner at erpicon.de
Thu Oct 16 15:50:54 PDT 2008
Hello list,
ยง6.7.8/17 of ISO/IEC 9899:1999 says:
"Each brace-enclosed initializer list has an associated current object.
When no designations are present, subobjects of the current object are
initialized in order according to the type of the current object: array
elements in increasing subscript order, structure members in declaration
order, and the first named member of a union. In contrast, a designation
causes the following initializer to begin initialization of the
subobject described by the designator. Initialization then continues
forward in order, beginning with the next subobject after that described
by the designator."
However, clang seems to expect the structure members to be initialized
in declaration order. Hence, the following test program will issue warnings:
--------8<--------
static int
test_funca(int *a)
{
return *a;
}
static int
test_funcb(char *b)
{
*b = 'a';
return 1;
}
struct test_ops {
int (*test_a)(int *);
int (*test_b)(char *);
};
struct test_ops test = {
.test_b = test_funcb,
.test_a = test_funca
};
int
main(void)
{
return 0;
}
-------->8--------
Swapping .test_b and .test_a in the initialization will silence the
warnings.
Regards,
Sascha
More information about the cfe-dev
mailing list