[asterisk-dev] gcc bug with zero-sized arrays and struct initializers.
Tony Mountifield
tony at softins.clara.co.uk
Tue Oct 30 07:51:56 CDT 2007
In article <20071030032741.A86261 at xorpc.icir.org>,
Luigi Rizzo <rizzo at icir.org> wrote:
> Some time ago i hit a problem with chan_iax which I eventually tracked
> down as related to the problem below - namely a compiler bug with
> struct initializers after zero-sized arrays.
>
> This was with gcc 2.95 - now, i know this is obsolete, but the bug is
> very subtle and it is unclear that other compiler versions are not
> affected.
>
> I am mentioning it in this list because this construct is used widely
> in asterisk (string fields have a zero-sized array used as a marker),
> and it would be good to check whether other compiler versions handle
> this correctly.
>
> cheers
> luigi
>
>
> /* This code shows a problem with gcc 2.95, 0-sized arrays and initializers:
> * Initializing a field right after a 0-sized array fails (the compiler emits
> * no code).
> */
>
> struct foo {
> char *pre[0];
> int a;
> };
Why would you want an element AFTER a zero-sized array? In the above
example, pre[0] would occupy the same storage as a.
Surely the zero-sized array is supposed to be the final item in the struct,
so that the struct defines the fixed part and the array then identifies the
beginning of the variable-length part.
Disclaimer: I haven't looked in Asterisk to see if it actually uses the
above construct, which just looks weird!
Cheers
Tony
--
Tony Mountifield
Work: tony at softins.co.uk - http://www.softins.co.uk
Play: tony at mountifield.org - http://tony.mountifield.org
More information about the asterisk-dev
mailing list