wrote:
> Hi,
>
> Can someone explain me why gcc-4.0 gives me the 'Initializer element is
> not constant' error with this code ? Everything seems to be constant
> here...
>
> #include <stdio.h>
> typedef struct { int a; int b;} t;
> int main(int argc, char** argv)
> {
> static t* array[2] = {
> (t[1]){ {1, 2} },
> (t[2]){ {3, 4}, {5, 6} } };
> return 0;
> }
Static objects (such as `array` in the program), when initialized,
require their initializers to be constant expressions. The elements of
`array` array are of type t*, a pointer, so their initializers should
be address constants. However, compound literals in a function are not
static objects, and thus the addresses are not constants and can not be
taken as the initializers.