This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Zero-length arrays
- To: Richard Kenner <kenner at vlsi1 dot ultra dot nyu dot edu>
- Subject: Re: Zero-length arrays
- From: Graham Stott <grahams at redhat dot com>
- Date: Thu, 04 Jan 2001 14:59:37 +0000
- Cc: gcc at gcc dot gnu dot org
- References: <10101041434.AA09538@vlsi1.ultra.nyu.edu>
Richard
Richard Kenner wrote:
>
> What *precisely*, are the semantics of this feature. Consider the following:
>
> struct foo {int a; int x[0]; int y;} xyz = {1, {2, 3, 4}, 5};
>
> int
> sub1 (struct foo *p)
> {
> return p->y;
> }
>
> This compiles with no errors with the current tree and XYZ contains in
> memory the integers 1 through 5 as consecutive words.
>
> But sub1 would return 2 when passsed &xyz, not the correct value of 5.
>
> Of course there's no way to support returning the proper value here, so I
> think the initializer should produce an error message.
I believe the zero-length arrays are only valid if they are the last
element of a structure which is not nested within another structure.
So I would agree your example should not compile hence we have a bug :-(
Graham