logoalt Hacker News

bluecalmlast Saturday at 7:53 PM1 replyview on HN

I think they are there to help the compiler so the optimizer might (but doesn't have to) assume they are true. It's sometimes very useful to be able to do so. For example if you know that two numbers are always different or that some value is always less than x. In standard C it's impossible to do but major compilers have a way to express it as extensions. GCC for example has:

  if (x)
    __builtin_unreachable();
C3 makes it a language construct. If you want runtime checks for safety you can use assert. The compiler turns those into asserts in safe/debug mode because that help catching bugs in non performance critical builds.

Replies

florianistlast Sunday at 12:41 AM

In the current C standard that's unreachable() from <stddef.h>

show 1 reply