B
Boon
Hello,
One of the examples in the C89 draft is
float y[4][3] = {
{ 1, 3, 5 },
{ 2, 4, 6 },
{ 3, 5, 7 },
};
is a definition with a fully bracketed initialization: 1, 3, and 5
initialize the first row of the array object y[0] , namely y[0][0] ,
y[0][1] , and y[0][2] . Likewise the next two lines initialize y[1]
and y[2] . The initializer ends early, so y[3] is initialized with
zeros. Precisely the same effect could have been achieved by
float y[4][3] = {
1, 3, 5, 2, 4, 6, 3, 5, 7
};
The initializer for y[0] does not begin with a left brace, so three
items from the list are used. Likewise the next three are taken
successively for y[1] and y[2] .
gcc seems to dislike the second form.
foo.c:2: warning: missing braces around initializer
foo.c:2: warning: (near initialization for 'y[0]')
AFAIU, a compiler is free to warn about anything, but this warning seems
somewhat wrong.
Would you consider a "bug" in gcc? (QoI perhaps.)
Regards.
One of the examples in the C89 draft is
float y[4][3] = {
{ 1, 3, 5 },
{ 2, 4, 6 },
{ 3, 5, 7 },
};
is a definition with a fully bracketed initialization: 1, 3, and 5
initialize the first row of the array object y[0] , namely y[0][0] ,
y[0][1] , and y[0][2] . Likewise the next two lines initialize y[1]
and y[2] . The initializer ends early, so y[3] is initialized with
zeros. Precisely the same effect could have been achieved by
float y[4][3] = {
1, 3, 5, 2, 4, 6, 3, 5, 7
};
The initializer for y[0] does not begin with a left brace, so three
items from the list are used. Likewise the next three are taken
successively for y[1] and y[2] .
gcc seems to dislike the second form.
foo.c:2: warning: missing braces around initializer
foo.c:2: warning: (near initialization for 'y[0]')
AFAIU, a compiler is free to warn about anything, but this warning seems
somewhat wrong.
Would you consider a "bug" in gcc? (QoI perhaps.)
Regards.