'Initializer lists in C and sequence points

The C Standard states that there is a sequence point at the end of a full expression in an initializer and that

initializer:

        assignment-expression

        { initializer-list }

        { initializer-list , }

initializer-list:

        initializer

        initializer-list , initializer

That would mean, however, that this

int a[2] = { i = 1 , ++i };

ought to be fine. Could someone please explain why, or why not, this is the case?



Solution 1:[1]

I do not know where you see that. I see https://port70.net/~nsz/c/c11/n1570.html#6.7.9p23 :

The evaluations of the initialization list expressions are indeterminately sequenced with respect to one another and thus the order in which any side effects occur is unspecified.

ought to be fine. Could someone please explain why

It is "fine", as in the behavior is defined to be unspecified behavior. You do not know, which one of i = 1 or ++i will execute first or last, one of them will.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 KamilCuk