+ 1

Undefined behaviour

when i compile int i = 0; i = i + i++; cout << i << endl ; via gcc and via clang-3.8 i get different results.

13th Apr 2017, 12:34 PM
Laura
1 Answer
+ 2
i think c/c++ language description has cases where the behaviour is not specified. in the example are rules like: evaluate from left to right, i++ increments i and returns the old value, + is commutative. but they are contradicting. so i think you can not guarantee the behaviour! it is undefined -
13th Apr 2017, 12:41 PM
Laura