Ruud Vlaming wrote:
On Thursday 24 September 2009 10:51, David Brown wrote:
As shown by the link you gave, zero-length arrays are only really valid
when they are the last element in a struct (they can be very useful there).
I cannot read any restrictions on the use of zero-length arrays. It states
"Zero-length arrays are allowed in GNU C" Period. And then an example
is discussed about how it can be usefull.
You are right - it is only flexible arrays (no length at all) that need
to be at the end of a struct. However, zero-length arrays are close to
the same thing as far as the compiler is concerned - they are only
actually /useful/ at the end of a struct.
The problem boils down to that C requires every declared object to have
a unique address. Theoretically, the compiler/linker could do this by
aliasing the zero-length array into the middle of something else that is
otherwise not addressed by the program. But in practice, it is done by
allocating at least 1 byte to zero-length data.
Maybe true, but contraditory to my findings with gcc. When i keep it
in the common (as is done automatically) gcc has no problems
whatsoever with the zero length array, and indeed it address may
overlap with other variables. It is up to the programmer i guess not
to misuse this 'feature'.
My question was, why is there a difference in behaviour, and i
hoped somebody could shine some light on this. But maybe
it is like J"org says, just a bug.
R.
I think it is more likely that the bug is that the zero-length arrays
take no space when allocated in "common", rather than that they /do/
take space when allocated elsewhere. So perhaps you should not protest
too loudly :-)
I suppose that since the standards don't allow zero-length arrays, I
their semantics are not very well defined.
_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list