This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Syntax error on struct variable initialization

I get syntax error for valid C-syntax. It seems like the compiler thinks that the initializer of the variable must come from a constant expression whereas a variable assignment should be accepted as well.

A workaround is to make the declaration separate from the initialization.

Same problem in both C51 and CX51.

foo_t f = {1, 2};
foo_t A[10] = { { 1, 2 } };

void foo(int i, foo_t* foo_p)
{
    foo_t x = f;    // C51: error C248: aggregate initialization needs curly braces
    foo_t y = A[i]; // C51: error C248: aggregate initialization needs curly braces
    foo_t z = foo_p[i]; // C51: non-address/-constant initializer
    foo_t w; w = foo_p[i]; // OK
}