initializing an array

William P. Reeder reeder at ut-emx.UUCP
Sat May 6 02:28:47 AEST 1989


I can initialize a simple array like this:
	int a[] = { 1, 2, 3 };
and C will figure out that a must have 3 elements.  But what if
my array has two dimensions?
	int a[][] = {
		{ 1, 2, 3 },
		{ 4, 5, 6 },
		{ 7, 8, 9 },
	};

It is possible to determine from the syntax how many elements there
are in each dimension, but my compiler complains about a null
dimension.

Section 8.6 of K&R (1st edition) says:

	When the declared variable is an aggregate (a
	structure or array) then the initializer consists
	of a brace-enclosed, comma-separated list of
	initializers for the members of the aggregate,
	written in increasing subscript or member order.
	If the aggregate contains subaggregates, this
	rule applies recursively to the members of the
	aggregate.

The last sentence claims that the initialization process is recursive.
Well, if determining the size of an (one dimensional) array can be done
during initialization, why not for the sub-array (a 2-d array is really
just an array of arrays, right?) ?

Any thoughts?  Please reply via e-mail to reeder at emx.utexas.edu
(or uunet!cs.utexas.edu!ut-emx!reeder) since I don't normally read
this group.

William Reeder, University of Texas at Austin, Computation Center
reeder at emx.utexas.edu
-- 
DISCLAIMER:	I speak only for myself, and usually only to myself.



More information about the Comp.lang.c mailing list