If I do something like this:
static int counter = 0;
counter = std::min(8, counter++);
I get a warning with g++ saying:
operation on 'counter' may be undefined [-Wsequence-point]
This works fine:
static int counter = 0;
counter++;
counter = std::min(8, counter);
Results are the same with ++counter
and/or std::max
.
I can't work out what's wrong with the first version. This also occurs with std::max. Just for an example, I get no warning when using functions from GLM.
Can anyone explain this a little bit for me? I'm using GCC 4.8 on Ubuntu 14.04.
EDIT: A bit more testing (which I should have done first)
If I do cntr = std::min(8, ++cntr);
, as I am in my actual application, printing the value after this line results in 1, then 2, then 3, etc. HOWEVER, if I do cntr = std::min(8, cntr++);
, the vaule is 0 EVERY TIME, it never increases at all.