Next: Integer Properties, Previous: Compile-time Assertions, Up: Particular Modules [Contents][Index]
A "non-returning" function is a function which cannot return normally.
Instead of returning, it can loop forever, or it can transfer control via
abort
, execvp
, exit
, longjmp
, throw
(in C++), or similar mechanisms. Non-returning functions are
declared with a void
return type.
It helps the compiler’s ability to emit sensible warnings, following data-flow analysis, to declare which functions are non-returning. It can also help generate more-efficient code, as there is no need to save a return address when calling a non-returning function.
Gnulib has multiple ways to support such a declaration:
_Noreturn
keyword. No modules are needed, as Gnulib
arranges for <config.h>
to define _Noreturn
to an
appropriate replacement on platforms lacking it.
Unfortunately, although this approach works for all current C versions,
the _Noreturn
keyword is obsolescent in C23.
_GL_NORETURN_FUNC
for use in function declarations and function
definitions.
_GL_NORETURN_FUNCPTR
for use on function pointers.
The include file is <noreturn.h>
.
Which of the approaches to use? If the non-returning functions you
have to declare are unlikely to be accessed through function pointers,
you should use _Noreturn
; otherwise the module
noreturn
provides for better data-flow analysis and thus for
better warnings.
There is also an obsolete stdnoreturn
module, but its use is no
longer recommended.