logoalt Hacker News

nmiloyesterday at 8:47 PM1 replyview on HN

If your assert compiles down to `if (condition) {}` in production then the compiler will optimize away the condition while keeping any side effects.


Replies

IshKebabyesterday at 10:57 PM

Yeah which may not be what you want. E.g. `assert(expensive_to_compute() == 0)`.

The correct way to solve this is with debug asserts (as in Rust, or how the parent described).

show 1 reply