Absurd declarations, and how gcc deals with them.

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

 



I have some auto-generated C code that contains declarations like:

   int x[0];
   int y[] = {};

With Microsoft compilers, both lines are illegal. The first produces the errors:

 error C2466: cannot allocate an array of constant size 0
 error C2133: 'x' : unknown size

and the second produces the error:

 error C2059: syntax error : '}'

What does gcc-3.x.x do with declarations like that (and why) ?
Is there a case for allowing such declarations to be made, or does Microsoft do the right thing by making them errors ?

I wrote the following test script:

-------------------------
#include <stdio.h>

int main(void) {
   int x[0];
   int y[] = {};

   printf("%d\n", y[0]);
   printf("%d\n", x[0]);

   printf("ok\n");
   return 0;
}

-------------------------

And built it (using the MinGW port of gcc-3.4.5) with :
 gcc -o try.exe -Wall try.c

No warnings were issued, and try.exe happily outputs:

1964975285
1965243500
ok

Cheers,
Rob

[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