4 ms·
> assert(x > 0 && "x was not greater than zero"); Shouldn't that be "||" rather than "&&"? We want the message only if the boolean expression is false.
by wpollock 6mo ago
> assert(x > 0 && "x was not greater than zero");
Shouldn't that be "||" rather than "&&"? We want the message only if the boolean expression is false.
- puschkinfr 6mo agoNo, because the string will be implicitly converted to `true` and `(a && true) == a` (for boolean `a`), so it will only be `false` if the assertion fails. Using || would always evaluate to `true`
- deleted 6mo ago[deleted]
- wpollock 6mo agoYou're right, thanks! This works too (but I wouldn't recommend it): assert( someBooleanExpression || ! "It is false" );