From my understanding, this program should have undefined behavior.
#include <stdio.h>
int main()
{
int a = 3, b = 3, c = 10, d = 20;
int e = (a++ * ++b)-((c / b) * a) + d;
printf("%d", e) ;
return 0;
}
The C99 standard §6.5 ¶2 says
Between the previous and next sequence point an object shall have its stored value modified at most once by the evaluation of an expression. Furthermore, the prior value shall be read only to determine the value to be stored.
So, in the line defining 'e'
, a
and b
are being read not only for determining what to store back in a
and b
, but also to compute the expression ((c / b) * a)
However, gcc does not give warning even with -Wsequence-point warning
.
What am I missing here?