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 }
But I also know that e.g. GCC is quite strict when told to be,
And it did warn about that code. Which all that the standard requires to happen in case of a constraint violation like this.
So it seems like more than one manufacturer has selected that interpretation.
This is not a matter of interpretation. It's a matter of compilers supporting more than the language requires them to. Code relying on such extensions is unportable. In stricter language, your code is not a fully conforming C program, and compilers can pretty much do with it whatever they like.
The important differences here is that the latter one uses expressions inside the aggregate whereas the first is a variable assignment.
Ahem, no. All three warnings/errors in the initial test case were about initialized definitions, not assignments.