Zero Length Arrays Allowed in C Standard?

adam.denton asd at cbnewsj.ATT.COM
Thu Dec 7 04:08:21 AEST 1989


In article <480 at codonics.COM> bret at codonics.com (Bret Orsburn) writes:
>In article <11715 at smoke.BRL.MIL> gwyn at brl.arpa (Doug Gwyn) writes:
>>In article <2298 at jato.Jpl.Nasa.Gov> baalke at mars.jpl.nasa.gov (Ron Baalke) writes:
>>>are zero length arrays allowed in the ANSI standard for C?
>>
>>No; Standard C does not support zero-sized objects.
>>
>
>Aargh! Whatever happened to "don't break existing code"?!
>
>What was the rationale behind this (IMHO) arbitrary obstruction?


Pardon me, but I just can't keep quiet any longer.

What fathomable purpose could a programmer possibly want by
declaring a zero-length array?  To store nothing?
Just what is a compiler supposed to do when it sees
  int a[0]; ??
Set `a' to point somewhere in memory (i.e., "allocate" this "array") ?
But since it's a zero-length
object, the compiler might well assign ANOTHER variable's location
to that same somewhere in memory.  And how could I assign something
to that location (which is dubious anyway%)?  C never allows assignment
to the name of an array.  `a' is not an lvalue.  And a[0] is not a member
of the array `a' !!  (or a[_anything_] for that matter!!)

I suspect the a[0] that the original poster found was a typo that
was never detected.

[End of my sermon on the mount.]
-------
% Akin to { int *p; *p = 3; } without p being malloc'ed.
-------

Adam S. Denton
asd at mtqua.ATT.COM

All flames are appreciated!  Please enclose $1.00 per flame to cover
processing and handling!!



More information about the Comp.lang.c mailing list