18 Language support library [language.support]

18.10 Other runtime support [support.runtime]

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 of a reference type, or of 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 <cstdalign> and the header <stdalign.h> shall not define a macro named alignas.

The header <cstdbool> and the header <stdbool.h> shall not define macros named bool, true, or false.

A call to the function signal synchronizes with any resulting invocation of the signal handler so installed.

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 plain lock-free atomic operations. A plain lock-free atomic operation is an invocation of a function f from Clause [atomics], such that f is not a member function, and either f is the function atomic_is_lock_free, or for every atomic argument A passed to f, atomic_is_lock_free(A) yields true. All signal handlers shall have C linkage. The behavior of any function other than a POF used as a signal handler in a C++ program is implementation-defined.229

Table 34 — Header <csetjmp> synopsis
TypeName(s)
Macro: setjmp
Type: jmp_buf
Function: longjmp

Table 35 — Header <csignal> synopsis
TypeName(s)
Macros: SIGABRT SIGILL SIGSEGV SIG_DFL
SIG_IGN SIGFPE SIGINT SIGTERM SIG_ERR
Type: sig_atomic_t
Functions: raise signal

Table 36 — Header <cstdalign> synopsis
TypeName(s)
Macro: __alignas_is_defined

Table 37 — Header <cstdarg> synopsis
TypeName(s)
Macros: va_arg va_end va_start
va_copy
Type: va_list

Table 38 — Header <cstdbool> synopsis
TypeName(s)
Macro: __bool_true_false_are_defined

Table 39 — Header <cstdlib> synopsis
TypeName(s)
Functions: getenv system

Table 40 — Header <ctime> synopsis
TypeName(s)
Macro: CLOCKS_PER_SEC
Type: clock_t
Function: clock

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]).