[asterisk-dev] gcc bug with zero-sized arrays and struct initializers.
Luigi Rizzo
rizzo at icir.org
Tue Oct 30 05:27:41 CDT 2007
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;
};
struct bar {
char *pre[1];
int a;
};
int main(int argc, char *argv[])
{
struct foo a = { .a = 123 };
struct bar b = { .a = 123 };
printf("a.a is %d, should be 123\n", a.a);
printf("b.a is %d, should be 123\n", b.a);
return 0;
}
More information about the asterisk-dev
mailing list