Headers <csetjmp> (nonlocal jumps), <csignal> (signal handling), <cstdalign> (alignment), <cstdarg> (variable arguments), <cstdbool> (__bool_true_false_are_defined). <cstdlib> (runtime environment getenv(), system()), and <ctime> (system clock clock(), time()) provide further compatibility with C code.
The contents of these headers are the same as the Standard C library headers <setjmp.h>, <signal.h>, <stdalign.h>, <stdarg.h>, <stdbool.h>, <stdlib.h>, and <time.h>, respectively, with the following changes:
The restrictions that ISO C places on the second parameter to the va_start() macro in header <stdarg.h> are different in this International Standard. The parameter parmN is the identifier of the rightmost parameter in the variable parameter list of the function definition (the one just before the ...).228 If the parameter parmN is declared with a function, array, or reference type, or with a type that is not compatible with the type that results when passing an argument for which there is no parameter, the behavior is undefined.
See also: ISO C 4.8.1.1.
The function signature longjmp(jmp_buf jbuf, int val) has more restricted behavior in this International Standard. A setjmp/longjmp call pair has undefined behavior if replacing the setjmp and longjmp by catch and throw would invoke any non-trivial destructors for any automatic objects.
See also: ISO C 7.10.4, 7.8, 7.6, 7.12.
Calls to the function getenv shall not introduce a data race ([res.on.data.races]) provided that nothing modifies the environment. [ Note: Calls to the POSIX functions setenv and putenv modify the environment. — end note ]
A call to the setlocale function may introduce a data race with other calls to the setlocale function or with calls to functions that are affected by the current C locale. The implementation shall behave as if no library function other than locale::global() calls the setlocale function.
The header <cstdbool> and the header <stdbool.h> shall not define macros named bool, true, or false.
The common subset of the C and C++ languages consists of all declarations, definitions, and expressions that may appear in a well formed C++ program and also in a conforming C program. A POF (“plain old function”) is a function that uses only features from this common subset, and that does not directly or indirectly use any function that is not a POF, except that it may use functions defined in Clause [atomics] that are not member functions. All signal handlers shall have C linkage. A POF that could be used as a signal handler in a conforming C program does not produce undefined behavior when used as a signal handler in a C++ program. The behavior of any other function used as a signal handler in a C++ program is implementation-defined.229
Type | Name(s) | |||
Macros: | SIGABRT | SIGILL | SIGSEGV | SIG_DFL |
SIG_IGN | SIGFPE | SIGINT | SIGTERM | SIG_ERR |
Type: | sig_atomic_t | |||
Functions: | raise | signal |
Type | Name(s) | ||
Macros: | va_arg | va_end | va_start |
va_copy | |||
Type: | va_list |
Note that va_start is required to work as specified even if unary operator& is overloaded for the type of parmN.
In particular, a signal handler using exception handling is very likely to have problems. Also, invoking std::exit may cause destruction of objects, including those of the standard library implementation, which, in general, yields undefined behavior in a signal handler (see [intro.execution]).