Alexandre Courbot
2003-10-07 14:32:54 UTC
Hello everybody,
Since a few versions, it appears that gcc doesn't allow anymore the
initialization of flexible array members. The following code did compile
under 2.95 but doesn't under 3.3.1:
typedef struct
{
char a;
char b;
int flexo[];
} EnclosedStruct;
typedef struct
{
int a;
int b;
EnclosedStruct s;
} MyStruct;
int main(int argc, char * argv[])
{
MyStruct toto = { 10, 20, { 'a', 'b', { 0, 1, 2, 3 } } };
}
$ gcc test.c -o test
test.c: In function `main':
test.c:17: error: initialization of flexible array member in a nested context
test.c:17: error: (near initialization for `toto.s.flexo')
test.c:17: error: non-static initialization of a flexible array member
test.c:17: error: (near initialization for `toto.s')
This is however something we *really* need to do, and consider safe since the
flexible member is located at the end of the enclosing structure. Is there
any workaround we could use, or do anybody have any advice to give to face
this situation?
Thanks in advance,
Alex.
Since a few versions, it appears that gcc doesn't allow anymore the
initialization of flexible array members. The following code did compile
under 2.95 but doesn't under 3.3.1:
typedef struct
{
char a;
char b;
int flexo[];
} EnclosedStruct;
typedef struct
{
int a;
int b;
EnclosedStruct s;
} MyStruct;
int main(int argc, char * argv[])
{
MyStruct toto = { 10, 20, { 'a', 'b', { 0, 1, 2, 3 } } };
}
$ gcc test.c -o test
test.c: In function `main':
test.c:17: error: initialization of flexible array member in a nested context
test.c:17: error: (near initialization for `toto.s.flexo')
test.c:17: error: non-static initialization of a flexible array member
test.c:17: error: (near initialization for `toto.s')
This is however something we *really* need to do, and consider safe since the
flexible member is located at the end of the enclosing structure. Is there
any workaround we could use, or do anybody have any advice to give to face
this situation?
Thanks in advance,
Alex.