Is there ANY difference whatsoever between:
if (!bool_function()) {
void_function();
}
and
bool_function() || void_function();
aside from readability?
May I use the 2nd form even though the second function is returning void?
Is it guaranteed in all C-based programming languages (C++, C#, Java) that the void_function does not get executed if the bool_function returns true?
EDIT: The reason why I'm asking is because on my C compiler is doesn't even give any warning, and it works as expected. I'm using IAR Embedded Workbench IDE.
Well, yes, the second doesn't compile.
You can't or a bool and a void.
UPDATE: You say your C compiler compiles this and it works fine. I doubt it. That is, I'm sure your compiler compiles it, but what is the result of bool || void? Is void always true? Always false? Sometimes one and sometimes the other?
In short - don't do it. Use the first form that tells everybody reading your code exactly what you're doing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With