flexible array members and initialization thereof

Richard Henderson rth@redhat.com
Sun Nov 19 15:49:00 GMT 2000


On Sun, Nov 19, 2000 at 04:21:04PM -0500, Richard Kenner wrote:
> It's fine with me.  Indeed, I was thinking of that but figured it would
> take too many other changes to work.

Right.  Well, fractionally more work was required to keep the
compiler from crashing on the attached test case.

Which leads to two other related changes.

One, on Oct 4 with my approval Will Cohen "clarified" the documentation
of the zero-length extension such that static initialization of such
arrays would not be supported.  While such initialization had not 
previously been documented, it had in fact worked -- at least some of
the time.  It was the appearence of a semi-nasty bug concerning the
initialization of bit-fields in this context that prompted me to take
the easy way out and support its removal.

However, this (arguably useful) feature is rather heavily used by glibc,
and with some prodding I agreed to officially support this as an extension.

Luckily for me, it appears that Mark "fixed" the aforementioned bit-field
bug on Oct 27 by deleting the old piece-at-a-time initialization code
entirely.  All that remained to make the extension work is supply
output_constant with a size for the array, which is easily done by
examining the contents of the constructor.

Two, ISO C99 supports GCC's zero-length array concept with what they
call "flexible array members".  The difference being that they place more
semantic restrictions on the containing structure, and that instead of
writing "int array[0]" you write "int array[]".

This patch adds enough code to support valid uses of flexible array
members; it does not add enough code to detect invalid uses.


r~


More information about the Gcc-patches mailing list