Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!caip!think!mit-eddie!genrad!decvax!mcnc!rti-sel!dg_rtp!throopw From: throopw@dg_rtp.UUCP (Wayne Throop) Newsgroups: net.lang.c Subject: Re: empty array declarations Message-ID: <633@dg_rtp.UUCP> Date: Tue, 14-Oct-86 14:07:01 EDT Article-I.D.: dg_rtp.633 Posted: Tue Oct 14 14:07:01 1986 Date-Received: Mon, 20-Oct-86 23:17:04 EDT References: <252@whuxcc.UUCP> Lines: 41 Summary: they are illegal > judah@whuxcc.UUCP (Judah Greenblatt) > Can anyone tell me why the following program is NOT in error? No, because it IS in error. > Can anyone tell me what it MEANS? No, because it is meaningless. (Please take both of the above answers to be flip or humorous.) More seriously, declaring an automatic array with the number of elements missing isn't stated explicitly to be an error in K&R, but we can infer that it is meaningless, since there is no way to deduce the array size by rules that *are* in K&R in such a case. And both H&S and the draft ANSI C standard explicitly make it illegal. SysV.2 lint and many pcc compilers fail to note this error, and seem to treat it as an array with no elements at all (and allocate no storage for it, only an address... any subscription of the array at all is out-of-bounds... not too useful). Some compilers that label a definition of an array with explicitly zero elements (as in "int a[0];") as an error nevertheless treat "int a[];" as an array with implicitly zero elements. "Hard to believe!" The DG C compiler says: int a[]; ^ You did not specify the array bounds for "a", either directly or implicity within an initialization. You can omit only the first bound of an extern declaration or the first bound after a pointer. The compiler used a bound of 1. which is a tad friendlier than what pcc compilers do with it, which is usually cause your program to blow up mysteriously later. -- There are two ways to write error-free programs; only the third one works. --- Alan J. Perlis -- Wayne Throop !mcnc!rti-sel!dg_rtp!throopw