This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C and zero-sized arrays - what is the standard?


Hi everybody,

Consider the following code:

struct MyStruct
{
    int a;
    int b[];
};

struct MyStruct i = { 10, {1, 2, 3, 4} };
struct MyStruct j = { 20, {10} };

int main(int argc, char * argv[])
{
    return 0;
}

This kind of code is very common in embedded systems programming. The above 
code works fine with GCC, but some other compilers require MyStruct to be 
declared as 

struct MyStruct
{
    int a;
    int b[0];
};

Is there a portable way to do this? What is the right form according to the 
standards?

Thanks,
Alex.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]