Consider the following simple program:
#include <stdio.h>
int main(void)
{
int a[5] = { a[2] = 1 };
printf("%d %d %d %d %d\n", a[0], a[1],a[2], a[3], a[4]);
}
With GCC 7.3.0 this outputs
1 0 1 0 0
Considering that a[1] is zero, it seems that the initialization is similar to
int a[5] = { 1 };
a[2] = 1;
The question is: While initializers could be any generic expression, in which order is the initialization and assignments made?
Is this even valid and well-defined? Could it be implementation-defined, undefined or maybe unspecified?
This question is related to the question Confusion about Array initialization in C.
int a[5] = { a[2] = 1, a[3] =2 };gives us1 2 0 0 0?!1 2 1 2 0for your code with GCC 5.4.0.