Is there any universal way to mark function as not returning

Viewed 55

When I simplify the example.. I have a function like:

void Crash(void) {
    exit(100);
}

And somewhere else code like:

...
if (val == NULL) Crash();
*val = something; // here I get the dereferencing NULL pointer warning

Is there any way how to mark the Crash function as escaping? So I would not have to write:

if (val == NULL) {
    Crash();
    return; // to avoid compiler's warnings
}
1 Answers

Since C11 there is _Noreturn and also #include <stdnoreturn.h> which comes with noreturn macro.

#include <stdnoreturn.h>

noreturn void Crash(void);
Related