[prev in list] [next in list] [prev in thread] [next in thread]
List: asterisk-dev
Subject: [asterisk-dev] gcc bug with zero-sized arrays and struct
From: Luigi Rizzo <rizzo () icir ! org>
Date: 2007-10-30 10:27:41
Message-ID: 20071030032741.A86261 () xorpc ! icir ! org
[Download RAW message or body]
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;
}
_______________________________________________
--Bandwidth and Colocation Provided by http://www.api-digital.com--
asterisk-dev mailing list
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo/asterisk-dev
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic