Editing here to clarify. The headline asks the question but the example given was not ideal. This was a more general Q than about the example code.
Compilers have sequence points, places where you can be assured that the equations have been evaluated etc and no lingering effects will occur: the compilation is stable. When I couldn't test the original example I went looking for theory, and came across SE/SO posts where there was some discussion about issues like:
int a = 1; int b = a++ - a++ + a++;
What would you expect the values of a and b to be after this? It turns out it hinges on whether the arithmetic operators are sequence points. Apparently this was not well settled in early versions of C, and in other languages (like Java) the results may differ yet again.
I now understand that an expression like
(item++ > max) contains no sequence points -- the
> operator does not trigger evaluation, but assignment operators and some arithmetic operators do.
I've read several Qs here concerning
++x but I don't see this specific case. I'm still something of a C novice here.
Do these two code fragments do the same thing?
// assume itemNum == maxItem on entry if (++itemNum > maxItem) itemNum = 0; if (itemNum++ > maxItem) itemNum = 0;
I gather that when the increment takes effect depends on the occurrence a 'sequence point' but I don't know if the comparison creates such an inflection.