Take the following code: struct f1 { int i; }; void f(void) { static struct f1 *f2 = &(struct f1){1}; } This is valid C99 at least according to both ICC and Comeau. And we acceptted it in 3.0.4 also.
Subject: Re: New: [3.4/4.0/4.1 Regression] Rejects valid C99 address of C99 struct in static variable in function On Sun, 17 Jul 2005, pinskia at gcc dot gnu dot org wrote: > Take the following code: > struct f1 > { > int i; > }; > void f(void) > { > static struct f1 *f2 = &(struct f1){1}; > } > > This is valid C99 at least according to both ICC and Comeau. So report it as a bug in ICC and Comeau. It is exactly as valid as struct f1 { int i; }; void f(void) { struct f1 tmp = { 1 }; static struct f1 *f2 = &tmp; } i.e. not at all. The address of an object of automatic storage duration is not a constant.
That is interesting as if we move the variable declaration out of the function, it works in GCC.
I believe you that this is invalid code.
Subject: Re: [3.4/4.0/4.1 Regression] Rejects valid C99 address of C99 struct in static variable in function On Sun, 17 Jul 2005, pinskia at gcc dot gnu dot org wrote: > That is interesting as if we move the variable declaration out of the > function, it works in GCC. That's because of 6.5.2.5#6 which defines the storage duration of compound literals to depend on whether they are inside a function: [#6] The value of the compound literal is that of an unnamed object initialized by the initializer list. If the compound literal occurs outside the body of a function, the object has static storage duration; otherwise, it has automatic storage duration associated with the enclosing block.