This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: What does zero-length array mean at file scope?
Dave Korn wrote:
> Dave Korn wrote:
>> Dave Korn wrote:
>>> I've read http://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html about six
>>> times and can't see anywhere it even hints that you can use this syntax
>>> anywhere except as the trailing member of a struct.
>> Andrew Haley wrote:
>>> But zero-length arrays are a gcc extension. There's nothing that limits
>>> them to the last member of a struct. zero-length arrays must be rejected
>>> with -pedantic, but not otherwise.
>>> Because it's a documented gcc extension.
>> Obviously I can't see for looking; can you please point me to the precise
>> chapter/page/paragraph/line that I should have found earlier?
"Zero-length arrays are allowed in GNU C. They are very useful as the
last element of a structure ..."
That doesn't in any way imply that the last element of a struct is the only
circumstance in which you may use a zero-length array.
> (I honestly mean that, no sarcasm intended; it was late at night and I was
> tired, I could easily have misread or overlooked something.) I did find this
> comment in varasm.c:assemble_noswitch_variable() that says we need to handle
> this case:
>
> /* Don't allocate zero bytes of common,
> since that means "undefined external" in the linker. */
> if (size == 0)
> rounded = 1;
>
> ... so I guess it counts as a backend bug if the backend still emits a zero in
> the .comm directive, and that the documentation of ASM_OUTPUT.*COMMON should
> probably be improved to warn of the danger that size may be zero.
Yes. That's what is usually done: all you have to do is fix the back end.
Andrew.