News for hackers. Stuff that matters.
Re:Catch-23: The New C Standard Sets the World on Fire by lionkor on Sunday April 02, 2023 @05:26AM (#35408703)
Respectfully, you would already be doing this in any C codebase, with `assert()`, right? We are all checking our preconditions with assert... right?
Re:Catch-23: The New C Standard Sets the World on Fire by pornel on Sunday April 02, 2023 @05:46AM (#35408842)
NDEBUG makes these checks disappear, so that's not an option for checks that are supposed to stay in the program.
Re:Catch-23: The New C Standard Sets the World on Fire by GuB-42 on Sunday April 02, 2023 @09:24AM (#35410259)
AFAIK, 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.