This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Initialization of nested flexible array members
- From: Alexandre Courbot <Alexandre dot Courbot at lifl dot fr>
- To: gcc-help at gcc dot gnu dot org
- Date: Tue, 7 Oct 2003 16:32:54 +0200
- Subject: Initialization of nested flexible array members
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.