1 || condition
always true, regardless of whether the condition true or not. In this case, condition never evaluated. The following code:
int c = 5; if (1 || c++){} printf("%d", c);
outputs 5 , since c never increases, however if you change 1 to 0 , c++ is actually called, making output 6 .
The usual practical use of this is in a situation where you want to test the part of the code that is called when a condition is satisfied that evaluates to only true:
if (1 || condition ) { // code I want to test }
This condition method will never be evaluated, and therefore // code I want to test always called. However, this is definitely not the same as:
if (condition) { ...
which is an instruction where condition will actually be evaluated (and in your case Foo will be called)
LihO Oct 10 '13 at 9:44 2013-10-10 09:44
source share