🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.c
Article #9597

Re: empty array declarations

#9597
From: throopw Wayne Throop
Date: Fri, 17 Oct 1986 20:56
41 lines
2353 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: <285@ndmce.uucp>
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!cuae2!ltuxa!we53!sw013b!dj3b1!killer!ndmce!pollux!infotel!ut-ngp!ut-sally!seismo!think!mit-eddie!genrad!decvax!mcnc!rti-sel!dg_rtp!throopw
References: <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!cuae2!ltuxa!we53!sw013b!dj3b1!killer!ndmce!pollux!infotel!ut-ngp!ut-sally!seismo!think!mit-eddie!genrad!decvax!mcnc!rti-sel!dg_rtp!throopw
From: throopw@dg_rtp.UUCP@ndmce.uucp (Wayne Throop)
Newsgroups: net.lang.c
Subject: Re: empty array declarations
Message-ID: <285@ndmce.uucp>
Date: Fri, 17-Oct-86 16:56:11 EDT
Article-I.D.: ndmce.285
Posted: Fri Oct 17 16:56:11 1986
Date-Received: Tue, 21-Oct-86 05:35:30 EDT
References: <252@whuxcc.UUCP>
Sender: news@ndmce.uucp
Organization: Nathan D. Maier Consulting Engineers, Dallas
Lines: 41
Summary: they are illegal