Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!cmcl2!husc6!rutgers!princeton!allegra!ulysses!bellcore!whuxcc!judah From: judah@whuxcc.UUCP (Judah Greenblatt) Newsgroups: net.lang.c Subject: empty array declarations Message-ID: <252@whuxcc.UUCP> Date: Fri, 10-Oct-86 17:13:34 EDT Article-I.D.: whuxcc.252 Posted: Fri Oct 10 17:13:34 1986 Date-Received: Sat, 11-Oct-86 20:48:40 EDT Distribution: net Organization: Bell Comm. Rsrch., Morristown, NJ Lines: 37 Can anyone tell me why the following program is NOT in error? Can anyone tell me what it MEANS? main() { int a[]; a[0] = 5; } Lint only complains about the random return value from main. Most c compilers I tried (3B20, CCI 6/32, Pyramid 98x) accepted and executed this program with no complaints. The Sequent compiler accepted the declaration and then gave a 'compiler error' message for the assignment. In K&R [1], section 8.4, it states: "..... the constant expressions which specify the bounds of the arrays may be missing .... This elision is useful when the array is external and the actual definition, which allocates storage, is given elsewhere. The first constant-expression may also be omitted when the declarator is followed by initialization." This wording seems to allow the array size to be omitted anyplace, but only assigns a meaning to the result for 'extern' arrays and where there is an initializer. I was recently bitten by code like this, and was wondering why it isn't illegal to do such things. ---------- [1] Kernighan, Brian W. and Dennis M. Ritchie, "The C Programming Language", Prentice-Hall, Inc., 1978 -- Judah Greenblatt "Backward into the Future!" Bell Communications Research uucp: {bellcore,infopro,ihnp4}!whuxcc!judah Morristown, New Jersey, USA arpa: whuxcc!judah@mouton.bellcore.com