Article View: net.lang.c
Article #9592Re: empty array declarations
From: Wayne Throop
Date: Tue, 14 Oct 1986 18:07
Date: Tue, 14 Oct 1986 18:07
41 lines
2183 bytes
2183 bytes
> 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 <the-known-world>!mcnc!rti-sel!dg_rtp!throopw
Technical Details
Message-ID:
<633@dg_rtp.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!watmath!clyde!caip!think!mit-eddie!genrad!decvax!mcnc!rti-sel!dg_rtp!throopwReferences:
<252@whuxcc.UUCP>Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!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