I am writing a compiler that matches, within the {} scope, by and large the semantics of C99. When trying to reverse-engineer how gcc handles certain undefined behavior, in particular chained before and after incrementing variables, I noticed that it is hopelessly confused if you combine this with changing assignments (for example, "* =",) and array access . Simplification to the simplest point of seeming complete confusion, gcc 4.6.3. evaluates (with and without the option -std = c99):
a[0] = 2;
a[0] *= a[0]++;
to
a[0] = 3.
Do I remember the standard wrong? Is any use of pre-or post-increment already undefined, and not just chained use in a compound expression?
Also, even if the "undefined" behavior above seems like a particularly bad way to calculate the result, since I could only see how you would justify the result 5 (= 2 * 2 + 1, then what I would do is post-increment after the assignment operator), or 6 (= 3 * 2, use the variable, and then immediately after increasing it and process it in parsing order - the parser almost certainly evaluates "* =" after evaluating the RHS expression). Any understanding of this is from the angle of C or C ++?
I noticed this when trying to combine arrays with integer bounds of expressions with preliminary and post-increment and implement it , it is really difficult ; but nonetheless, the above seems a bit like copying, given the flagship status of gcc.
This is under Ubuntu 12.04.
: , gcc , . , , , : (1) ; (2) ; (3) . , , " ".
: clang 6. clang, , , , .