Multidimensional Static Array Initi
joe at modcomp.UUCP
joe at modcomp.UUCP
Sat Aug 27 15:29:00 AEST 1988
Tim Graham (jpl-devvax.UUCP!timg) writes:
>...
>I am not under the impression that C multi-dimensional arrays are
>non-rectangular; it is precisely because of their rectangularity
>that it appears so easy to implement initialization in a manner
>analogous to 1-D static array (without size declarator) initialization.
>
>For example, if we have the declaration
>
> int foo[][4] = { { 1, 2, 3, 4 },
> { 5, 8 },
> { 9, 10, 12 } };
>
>then the unitialized elements in the 3x4 array are filled with zeros. Is
>it really that much harder for it to be possible to implement a declaration
>like
>
> int foo[][] = { { 1, 2, 3, 4 },
> { 5, 8 },
> { 9, 10, 12 } };
>
>and have it do exactly the same thing without the bother of me having to ...
C, unfortunately, lets the user drop the inner braces whenever they are
"unnecessary", that is, whenever enough arguments are present to completely
fill the current dimension or the current structure. For example, the above
fragment could have been written as:
int for[3][4] = { 1, 2, 3, 4,
{ 5 , 8 },
9 , 10 , 12 };
This feature makes automatic dimension counting difficult or impossible,
at least without an (X3J11) language change forbidding it for arrays with
multiple uninitialized dimensions.
--
Joe Korty "flames, flames, go away
uunet!modcomp!joe come back again, some other day"
More information about the Comp.lang.c
mailing list