I have written a program that lists errors in a set of stuff, and returns a boolean value at the end (returning true means that no error has been found).
Here is a summary of my code :
bool checkStuff1() {/*...*/}
bool checkStuff2() {/*...*/}
// ...
bool checkStuffN() {/*...*/}
bool checkAllStuff()
{
bool result = true;
result &= checkStuff1();
result &= checkStuff2();
// ...
result &= checkStuffN();
return result;
}
I have confidence the value of result
will be the right one at the end. However, I would like to be sure that all the functions checkStuffX()
are called (because they print error messages when failing, and I would like all the error messages to be printed).
I know that if I wrote this way, it would skip all checkStuffX()
after the first one failing :
result = result && checkStuffX(); // Will not call checkStuffX() if result is already false
I also know that if I wrote this way, it will call all checkStuffX()
functions :
result = checkStuffX() && result; // Will always call checkStuffX() even if result is false
But I was wondering if the behaviour of the code I am using, with bitwise comparison, was determined and guaranteed by the standard ?
Or is there a risk of undefined behaviour, depending on the compiler used and its optimisations ?