Array Initialization warnings
Oliver Kullmann
O.Kullmann@swansea.ac.uk
Sun Apr 21 00:52:00 GMT 2002
> Hi David,
>
> > Just to clarify...the standard requires the brackets be placed as in
> > your example? If so, guess I had best get to bracketing my arrays.
> >
> It is pretty much up to you, how you handle your arrays. You can
> certainly use multi dimentional arrays and initialise them as such,
> or you could use one dimentional arrays and initialise them as such.
> There is nothing wrong with interpreting an x dimentional array as an
> y dimentional array, i am just saying, that you ought to be consistent.
> Your original code depended on a particular physical layout of the
> array. I am not sure, that physical layout is required by the standard.
>
> >I really did not want to have to go back and recode my array that looks
> >like this:BYTE SUBIMG_NTSC[2][2][4][3][8] = {...
>
> You might want to wait with a rewrite, until someone makes
> a stronger statement about this;)
>
> Yours sincerely,
> bjorn
Hi,
I copied a paragraph from the standard (ISO/IEC 14882:1998(E)):
When initializing a multi-dimensional array, the initializers
initialize the elements with the last (rightmost) index of the array
varying the fastest (8.3.4).
[Example: int x[2][2] = { 3, 1, 4, 2 };
initializes x[0][0] to 3, x[0][1] to 1, x[1][0] to 4, and x[1][1] to 2.
On the other hand,
float y[4][3] = { { 1 }, { 2 }, { 3 }, { 4 } };
initializes the first column of y (regarded as a two-dimensional array) and
leaves the rest zero. ]
(paragraph 8.5.1)
Oliver
More information about the Gcc-help
mailing list