[cfe-dev] Compound Literal semantic analysis...

Eli Friedman eli.friedman at gmail.com
Fri Jan 11 12:22:28 PST 2008


On Jan 11, 2008 11:38 AM, Steve Naroff <snaroff at apple.com> wrote:
> void a(void) {
> int explicit;
> int anylocal;
> static int *t = &explicit;    // error for explicit automatic variables.
> static int *a = (int[]){anylocal};    // implicit automatic variable.
> EDG and NEILCC permit this, while GCC error.
> }
>
> Is my analogy flawed? Since the compound literal can refer to any
> local variable, I don't see how it could ever be constant...

http://www.comeaucomputing.com/tryitout/ over the following:

void a(void) {
int anylocal;
static int *a = (int[]){anylocal};
}

gives the following (in C99 mode):

"ComeauTest.c", line 3: error: expression must have a constant value
  static int *a = (int[]){anylocal};
                          ^

"ComeauTest.c", line 3: warning: variable "a" was declared but never referenced
  static int *a = (int[]){anylocal};

What were you testing with?

-Eli



More information about the cfe-dev mailing list