Path: utzoo!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!pasteur!ames!ncar!tank!oddjob!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: Multidimensional Static Array Initialization Follow-up Message-ID: <13219@mimsy.UUCP> Date: 25 Aug 88 18:12:16 GMT References: <2682@jpl-devvax.JPL.NASA.GOV> <13060@mimsy.UUCP> <8584@ihlpb.ATT.COM> <8596@ihlpb.ATT.COM> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 39 >In article <13149@mimsy.UUCP> chris@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@ihlpb.ATT.COM> tainter@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@mimsy.umd.edu Path: uunet!mimsy!chris