This code has an interesting bug:
some_struct struct_array1[10] = {0};
some_struct struct_array2[10] = {0}
int i;
for (i = 0;
i < sizeof(struct_array1) / sizeof(struct_array1[0]);
struct_array1[i].value = struct_array2[i++].value = 1)
;
For most compilers, the above code results in setting the "value" field of all structs in the respective arrays to 1. However, for one specific compiler (let's call it xcc), the structs in struct_array1 are NOT initialized correctly. The "value" field is set to 0 for all structs, which kind of surprised me.
The following code snippet works as expected on all compilers:
for (i = 0;
i < sizeof(struct_array1) / sizeof(struct_array1[0]);
i++)
{
struct_array1[i].value = struct_array2[i].value = 1;
}
Now, am I completely off here, or does the offending compiler "xcc" simply display a bug?
I can't find anything that displays implementation-specific behavior in the first code snippet; from what I understand the postfix incrementation should have precedence over the assignments, and the assignments should be evaluated right-to-left. There should be nothing wierd with the first code snippet, except that it's a tad unreadable.