3 ms·
Also variable assignment with identifier list: a = 0; x = (type_t) { .y = a++, .x = a++ } Now, figure it out the order of the field's assignment.
by piadodjanho 7y ago
Also variable assignment with identifier list:
a = 0;
x = (type_t) { .y = a++, .x = a++ }
Now, figure it out the order of the field's assignment.
- kazinator 7y agoThe order of evaluation among initializers is unspecified, which makes it UB. We don't have to use mixed-up designated initializers to run aground. Just simply: { int a = 0; int x[2] = { a++, a++ }; } This was also new in C99 (not to mention the struct literal syntax); in C90, run-time values couldn't be used for initializing aggregate members, so the issue wouldn't arise. Code like: { int a = 0; struct foo f = { a, a }; } was supported in the GNU C dialect of C90 before C99 and of course is also a long-time C++ feature. https://gcc.gnu.org/onlinedocs/gcc/Initializers.html#Initializers https://gcc.gnu.org/onlinedocs/gcc/Initializers.html#Initial... The doc doesn't say anything about order. I can't remember what C++ has to say about this.