Static intialization of flexible arrays in C++

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux