c / expert
Snippet
The _Noreturn Function Specifier
The _Noreturn keyword (C11) indicates that a function will not return to its caller, typically because it terminates the program or performs a long jump. This provides a hint to the compiler for optimization, allowing it to omit unnecessary code following the call and providing better static analysis for control flow.
snippet.c
1
2
3
4
5
6
7
#include <stdlib.h>#include <stdio.h>_Noreturn void panic(const char *msg) {fprintf(stderr, "FATAL: %s\n", msg);abort();}
Breakdown
1
_Noreturn void panic(const char *msg)
Specifies that the function 'panic' execution path never reaches the return statement.
2
abort();
A standard library function that terminates the process, satisfying the _Noreturn contract.