Auto variable with sizeof == 0

pinkas at mipos3.UUCP pinkas at mipos3.UUCP
Thu Feb 5 04:30:53 AEST 1987


In article <5258 at mimsy.UUCP> chris at mimsy.UUCP (Chris Torek) writes:
>In article <4114 at brl-adm.ARPA> escott%deis.uci.edu at icsg.uci.edu
>(Scott Menter) writes:
>>... is there any reason why you should be able to declare an array
>>with zero elements as an automatic variable?
>
>Why not?  It makes sense.  Perhaps it should elicit a warning, since
>no members of that array are accessible:  Valid subscripts are in the
>range [0..0).

Wrong.  There are no valid subscripts to the array.  To allow a subscript
of 0, the array must be declared as bar[1].  Remember, the valid subscripts
of an array declared foo[n] are [0..n1].

Regarding this problem, in a former posting I mentioned that the
declaration of struct foo **bar[] as an auto variable would be useful as a
dynamic array.  I have since been corrected.  Someone (I deleted the mail
message, so I don't have your name, sorry) pointed out that K&R stat that
an array is a constant and is thus unusable as an lvalue.  To make a
dynamic array, the declaration should read struct foo ***bar.  When
malloc'ed, it will yield an array of pointers to pointers to struct foo.

-Israel
-- 
----------------------------------------------------------------------
UUCP:	{amdcad,decwrl,hplabs,oliveb,pur-ee,qantel}!intelca!mipos3!pinkas
ARPA:	pinkas%mipos3.intel.com at relay.cs.net
CSNET:	pinkas%mipos3.intel.com



More information about the Comp.lang.c mailing list