P
Paul Jackson
Here's a brace-enclosed initialiser for a 3D array:
int a4[2][3][4] = {
{ 1, 2, 3, 4, {5, 6, 7 }, },
{ {13, 14, 15 }, 17, 18, 19, 20, {21, 22, 23, 24} }};
gcc produces some warnings when compiling this, but sets a4 to this,
which is what I'd expect:
{ { 1 2 3 4 } { 5 6 7 0 } {0 0 0 0 } }
{ {13 14 15 0 } {17 18 19 20 } {21 22 23 24 } }
It gets more interesting if I leave out initialiser '20':
int a4[2][3][4] = {
{ 1, 2, 3, 4, {5, 6, 7 }, },
{ {13, 14, 15 }, 17, 18, 19, {21, 22, 23, 24} }};
gcc now produces lots more warnings, and sets a4 to this:
{ { 1 2 3 4 } { 5 6 7 0 } { 0 0 0 0 } }
{ {13 14 15 0 } {17 18 19 21 } { 0 0 0 0 } }
Any ideas on what the 'correct' behaviour here should be? I've only
checked 6.7.8 in the C99 spec, but this seems to be wrong. I suspect
that either reporting an error or setting a4 to
{ { 1 2 3 4 } { 5 6 7 0 } { 0 0 0 0 } }
{ {13 14 15 0 } {17 18 19 0 } {21 22 23 24 } }
would have better.
Thanks -
Paul
int a4[2][3][4] = {
{ 1, 2, 3, 4, {5, 6, 7 }, },
{ {13, 14, 15 }, 17, 18, 19, 20, {21, 22, 23, 24} }};
gcc produces some warnings when compiling this, but sets a4 to this,
which is what I'd expect:
{ { 1 2 3 4 } { 5 6 7 0 } {0 0 0 0 } }
{ {13 14 15 0 } {17 18 19 20 } {21 22 23 24 } }
It gets more interesting if I leave out initialiser '20':
int a4[2][3][4] = {
{ 1, 2, 3, 4, {5, 6, 7 }, },
{ {13, 14, 15 }, 17, 18, 19, {21, 22, 23, 24} }};
gcc now produces lots more warnings, and sets a4 to this:
{ { 1 2 3 4 } { 5 6 7 0 } { 0 0 0 0 } }
{ {13 14 15 0 } {17 18 19 21 } { 0 0 0 0 } }
Any ideas on what the 'correct' behaviour here should be? I've only
checked 6.7.8 in the C99 spec, but this seems to be wrong. I suspect
that either reporting an error or setting a4 to
{ { 1 2 3 4 } { 5 6 7 0 } { 0 0 0 0 } }
{ {13 14 15 0 } {17 18 19 0 } {21 22 23 24 } }
would have better.
Thanks -
Paul