Static intialization of flexible arrays in C++

Nitin Karkhanis nkarkhan@yahoo.com
Sun Feb 13 23:07:00 GMT 2005


Hi,

I am porting a bunch of C files from a “C” compiler
environment to an environment where C++ compiler is
used to compile all files.

Gcc version used is 3.3.1 

Static initializations of a flexible array works with
gcc but not with g++ . is this by design?

 

Sample code

#include <stdlib.h>

#include <stdio.h>

 

typedef struct {

    int A;

    int Data[];

} flex_array;

 

flex_array a = {1,{1,2,3}};

 

int main (__attribute__((__unused__)) int argc,
__attribute__((__unused__)) char *argv[])

{

    int i;

    for (i =0; i <3; i++) {

        printf("%d\n", a.Data);

    }

    return 0;

}

 

 

Compiler error with g++ is 

 

 test_flex.c:9: error: excess elements in aggregate
initializer

with gcc it compiles just fine.

If this is indeed the desired behaviour than are there
any suggested workarounds?


Thank you,
Nitin.


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the Gcc-help mailing list