logoalt Hacker News

wpollockyesterday at 9:04 PM1 replyview on HN

> 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.


Replies

puschkinfryesterday at 9:17 PM

No, 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`

show 2 replies