Zero Length Arrays Allowed in C Standard?

c9h at psuecl.bitnet c9h at psuecl.bitnet
Thu Dec 7 09:21:05 AEST 1989


> <1989Dec5.112553.24087 at twwells.com> <11963 at phoenix.Princeton.EDU> <8141 at cg-atla.UUCP> <11759 at smoke.BRL.MIL>
Organization: Engineering Computer Lab, Pennsylvania State University
Lines: 25

In article <11759 at smoke.BRL.MIL>, gwyn at smoke.BRL.MIL (Doug Gwyn) writes:
>
> The main problem is that two distinct 0-length objects might have
> the same address.  This bothers some people.

In *most* compilers, a 0-length array would share the same address as the
next data item defined after it.  However, you should not rely on this,
because it may be non-portable.

It seems that the main reason (and *only* even half-way decent reason) for
using a 0-length array is to allocate a variable amount of memory for a
structure depending on the length of the array.  This seems reasonable.

However, as usual, some compilers try to protect the dumb, stupid, idiotic,
crazed, terminal-bashing, cpu-smashing programmer from making such a stupid
mistake.  (BTW: I'm being sarcastic.)  Hell, C doesn't do any other array
bounds checking; why should it bother me about something like this?

As far as I'm concerned, your compiler is broken.

--
- Charles Martin Hannum II       "Klein bottle for sale ... inquire within."
    (That's Charles to you!)     "To life immortal!"
  c9h at psuecl.{bitnet,psu.edu}    "No noozzzz izzz netzzzsnoozzzzz..."
  cmh117 at psuvm.{bitnet,psu.edu}  "Mem'ry, all alone in the moonlight ..."



More information about the Comp.lang.c mailing list