The C18 Standard states at 6.7.9/2
that:
No initializer shall attempt to provide a value for an object not contained within the entity being initialized.
It is not really clear what it means. There is a related topic: Incosistent gcc diagnostic for string initialization. The clause I cited was used to explain the error produced by the following initialization:
//error: excess elements in array initializer char a[5]
char a[5] = {'h','e','l','l','o','\0'};
Where the initializer-list
has length exceeding the size of the array being initialized.
But consider more trivial example:
int main(void){
int a;
int b = (a = 3);
}
The initializer here is (a = 3)
which is an assignment-expression
. And the initializer assigns a value to another object which should cause constraint-violation.
Why isn't any diagnostic printed?