3 ms·
What really costs nothing is putting assert(0) in any place that should be unreachable. For example: switch (...) { case A: ... case B: .
by parenthesis 6y ago
What really costs nothing is putting assert(0) in any place that should be unreachable. For example:
switch (...) {
case A:
...
case B:
...
...
default: // all possible cases are dealt with above
assert(0);
}
- identity0 6y agoOne ugly trick for unreachable branches is this: assert(!"You gave an invalid letter"); The string literal is a pointer, so !pointer is false. And then you get a nice explanation message when the assertion fails. I wish all assert gave optional explanation messages.
- saagarjha 6y agoI often do assert(condition && "String explanation") myself.