Multidimensional Static Array Initialization Follow-up

Tainter tainter at ihlpb.ATT.COM
Wed Aug 24 14:26:27 AEST 1988


In article <13149 at mimsy.UUCP> chris at mimsy.UUCP (Chris Torek) writes:
>[questions and answers about when array sizes can be elided deleted]

>In article <8584 at ihlpb.ATT.COM> tainter at ihlpb.ATT.COM (Tainter) writes:
>>It isn't just an issue of the initializer.  Consider code referencing the
>>above entity foo.  As long as only one dimension is unknown C can generate
>>code to manipulate the structure without requiring patching at link time.

>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.

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.

Thus for security in the code you should explicitly declare the dimension
in both places (extern declaration and the definition) using a macro,
included into both files.  Therefore, to encourage this, the language should,
and does require all lower dimensions.  Or better yet use a typedef!

Of additional interest, what does one do with function parameters if the
lesser dimensions are not explicitly declared?  Again one wants to encourage
use of a common dimension definition.

>In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)

--j.a.tainter
ihlpb!tainter



More information about the Comp.lang.c mailing list