I have this line of code:
front = (++front) % size;
In C I get no warnings but in C++ I get the warning operation on front may be undefined [-Wsequence-point]
. How does this preincrement usage cause undefined behavior? In my mind, this line is very unambiguous and will be interpreted as:
- increment front
- mod front with size
- assign new value to front.
Is my compiler just throwing a blanket warning?
P.S. I understand the warning if I were doing something like front = front++;
or Heaven forbid front = front++ + front++;
.
EDIT: This warning was produced in CodeBlocks on Windows 64 using GCC (tdm-1) 4.6.1