bitwise-or

Does bitwise-or guarantee an evaluation ordering?

你说的曾经没有我的故事 提交于 2019-12-01 02:38:56
Say I have this code: unsigned int func1(); unsigned int func2(); unsigned int func3(); unsigned int x = func1() | func2() | func3(); Does C++ guarantee that func1() will be called first, then func2(), and then func3()? Or is the compiler allowed to call the functions in any order it feels like? Also, is the compiler allowed to implement a short-circuit optimization here if it wants to? (e.g. if func1() returned ~0, could the compiler decide not to bother calling func2() or func3(), because it knows their return values can't possibly affect the value assigned to x?) No, there is no guarantee