mardi 30 octobre 2018

c++11 Order of evaluation (undefined behavior)

vec[ival++] <= vec[ival]

This expression has undefined behavior, because the order of evaluation of operator (<=)'s operands is undefined.

How can we rewrite that expression to avoid the undefined behavior? I've found an answer that appears to work:

vec[ival] <= vec[ival + 1]

If that is the right way to avoid the undefined behavior, why does rewriting it that way avoid the undefined behavior?

Adding any reference about how to fix that expression would be great.

Aucun commentaire:

Enregistrer un commentaire