When should the function attribute noreturn be used in C?
c, function, void
Solution
Don't do that for your `void` functions, this would have undefined behavior.
The new C11 construct `_Noreturn` should only be used when you know that your function will never return to the caller. This can e.g be the case when it unconditionally makes a call to `abort`, `exit` or alike, or when you enter an infinite loop.
The purpose of that is that the compiler can optimize the call on the calling side, in particular by cutting off the whole branch of execution that comes after the call.
Generally `void` functions are not of that kind, they return to the caller, just that on that return they don't provide a value that will be used. For most such functions declaring them is fundamentally wrong.
The C11 syntax is `_Noreturn` or with a macro `noreturn`. Not all compilers do yet implement that feature, but most have extensions to C99 (or C89) that provides the same feature. On that platforms you can usually define a macro `noreturn` that would be an upward compatible replacement.
Problem
I've recently found out about the `noreturn` attribute (I'm referring to C language, and not to C++ language; I'm working on a C project which uses a library where an equivalent is defined and it's destined only for C usage). When is it considered good practice to use the `noreturn` attribute? In all void function declarations? Are there any exceptions?