Auto variable with sizeof == 0

Chris Torek chris at mimsy.UUCP
Mon Feb 2 11:53:48 AEST 1987


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).

>What's strange is that, on the VAX, the program apparently successfully
>dereferenced bar, both setting a value for "*bar" and then using that value
>later.  How can this be right?

Just luck.

>And, just for the heck of asking, does ANSI C let you make such a
>declaration?

There seems to be a great debate over malloc(0), with some support
as well for empty arrays.  It is trivial to allow either, or to
disallow either; some argue in favour of `catching the programmer's
mistakes for him', while others argue that the construct may not
be a mistake, or may have been written by a machine, and that having
special cases for zero is both unnecessary and ugly.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690)
UUCP:	seismo!mimsy!chris	ARPA/CSNet:	chris at mimsy.umd.edu



More information about the Comp.lang.c mailing list