Multidimensional Static Array Initialization Follow-up

Chris Torek chris at mimsy.UUCP
Fri Aug 26 04:12:16 AEST 1988


>In article <13149 at mimsy.UUCP> chris at mimsy.UUCP (Chris Torek) writes:
>>The question was about initialised arrays---specifically, about the
>>cases where the compiler is able to deduce the dimensions.  Hence
>>*none* of the dimensions are unknown; they are merely left up to the
>>compiler to count.

[Note: this is not legal C, although there is, in my opinion, no
really compelling reason for that status.  Read on:]

In article <8596 at ihlpb.ATT.COM> tainter at ihlpb.ATT.COM (Tainter) writes:
>Which is all well and good for the module allocating the object and
>initializing it, but what about other modules declaring it extern?
>Those are the ones that end up needing the patching at link time.

Those are illegal.

>Thus for security in the code you should explicitly declare the dimension
>in [all] places ... [using some form of common definition].  Therefore,
>to encourage this, the language should, and does require all lower dimensions.

But if all the code that manipulates the array is in one module, why
not allow the compiler to do the counting?  If we decide that getting
the proper dimensions out of one module and into another is too hard to
assign to the compiler, yes, that leaves the language inconsistent in a
way, but is it not now inconsistent in a similar way in that it allows
you to elide some dimension, but not any number of dimensions?

>Of additional interest, what does one do with function parameters if the
>lesser dimensions are not explicitly declared?

One generates an error, and refuses to compile the code.

	% cat foo.c
	f(a) int a[][]; {}
	% cc foo.c
	"foo.c", line 1: null dimension
	%
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list