3 ms·
Respectfully, you would already be doing this in any C codebase, with `assert()`, right? We are all checking our preconditions with assert... right?
by lionkor 4y ago
Respectfully, you would already be doing this in any C codebase, with `assert()`, right? We are all checking our preconditions with assert... right?
- pornel 4y agoNDEBUG makes these checks disappear, so that's not an option for checks that are supposed to stay in the program.
- GuB-42 4y agoAFAIK, assert() is not undefined behavior, so it can't be used for optimization. It is either implementation-defined in debug mode, or does nothing in release mode. For example: assert(a >= 0); if (a < 0) printf("a is negative"); In release mode, assert() will be gone, so the if/printf() will stay. If we used "if (a < 0) unreachable();" instead of assert(), it would optimize away both lines.