4 ms·
> 1+1=1? True + True = True, because "true" means "not zero" and "false" means "zero". In most all languages that permit int->bool casting, if(2) will evaluate
by LeifCarrotson 3y ago
> 1+1=1?
True + True = True, because "true" means "not zero" and "false" means "zero". In most all languages that permit int->bool casting, if(2) will evaluate to "true".
The warnings clang and FCC generate are a style warning because it's unclear on casual reading. Even readers who know the precedence rules will typically want to insert the parentheses manually. If the meaning were undefined, the compiler would give an error, not a warning.
- hinkley 3y agoIt’s true as long as you don’t chain more than a couple billion Boolean checks. More importantly, only if you don’t rely on short circuiting logic.