17 Language support library [support]

17.2 Common definitions [support.types]

17.2.1 Header <cstddef> synopsis [cstddef.syn]

// all freestanding namespace std { using ptrdiff_t = see below; using size_t = see below; using max_align_t = see below; using nullptr_t = decltype(nullptr); enum class byte : unsigned char {}; // [support.types.byteops], byte type operations template<class IntType> constexpr byte& operator<<=(byte& b, IntType shift) noexcept; template<class IntType> constexpr byte operator<<(byte b, IntType shift) noexcept; template<class IntType> constexpr byte& operator>>=(byte& b, IntType shift) noexcept; template<class IntType> constexpr byte operator>>(byte b, IntType shift) noexcept; constexpr byte& operator|=(byte& l, byte r) noexcept; constexpr byte operator|(byte l, byte r) noexcept; constexpr byte& operator&=(byte& l, byte r) noexcept; constexpr byte operator&(byte l, byte r) noexcept; constexpr byte& operator^=(byte& l, byte r) noexcept; constexpr byte operator^(byte l, byte r) noexcept; constexpr byte operator~(byte b) noexcept; template<class IntType> constexpr IntType to_integer(byte b) noexcept; } #define NULL see below #define offsetof(P, D) see below
The contents and meaning of the header <cstddef> are the same as the C standard library header <stddef.h>, except that it does not declare the type wchar_t, that it also declares the type byte and its associated operations ([support.types.byteops]), and as noted in [support.types.nullptr] and [support.types.layout].
See also: ISO/IEC 9899:2018, 7.19

17.2.2 Header <cstdlib> synopsis [cstdlib.syn]

namespace std { using size_t = see below; // freestanding using div_t = see below; // freestanding using ldiv_t = see below; // freestanding using lldiv_t = see below; // freestanding } #define NULL see below // freestanding #define EXIT_FAILURE see below // freestanding #define EXIT_SUCCESS see below // freestanding #define RAND_MAX see below #define MB_CUR_MAX see below namespace std { // Exposition-only function type aliases extern "C" using c-atexit-handler = void(); // exposition only extern "C++" using atexit-handler = void(); // exposition only extern "C" using c-compare-pred = int(const void*, const void*); // exposition only extern "C++" using compare-pred = int(const void*, const void*); // exposition only // [support.start.term], start and termination [[noreturn]] void abort() noexcept; // freestanding int atexit(c-atexit-handler* func) noexcept; // freestanding int atexit(atexit-handler* func) noexcept; // freestanding int at_quick_exit(c-atexit-handler* func) noexcept; // freestanding int at_quick_exit(atexit-handler* func) noexcept; // freestanding [[noreturn]] void exit(int status); // freestanding [[noreturn]] void _Exit(int status) noexcept; // freestanding [[noreturn]] void quick_exit(int status) noexcept; // freestanding char* getenv(const char* name); int system(const char* string); // [c.malloc], C library memory allocation void* aligned_alloc(size_t alignment, size_t size); void* calloc(size_t nmemb, size_t size); void free(void* ptr); void* malloc(size_t size); void* realloc(void* ptr, size_t size); double atof(const char* nptr); int atoi(const char* nptr); long int atol(const char* nptr); long long int atoll(const char* nptr); double strtod(const char* nptr, char** endptr); float strtof(const char* nptr, char** endptr); long double strtold(const char* nptr, char** endptr); long int strtol(const char* nptr, char** endptr, int base); long long int strtoll(const char* nptr, char** endptr, int base); unsigned long int strtoul(const char* nptr, char** endptr, int base); unsigned long long int strtoull(const char* nptr, char** endptr, int base); // [c.mb.wcs], multibyte / wide string and character conversion functions int mblen(const char* s, size_t n); int mbtowc(wchar_t* pwc, const char* s, size_t n); int wctomb(char* s, wchar_t wchar); size_t mbstowcs(wchar_t* pwcs, const char* s, size_t n); size_t wcstombs(char* s, const wchar_t* pwcs, size_t n); // [alg.c.library], C standard library algorithms void* bsearch(const void* key, const void* base, size_t nmemb, size_t size, // freestanding c-compare-pred* compar); void* bsearch(const void* key, const void* base, size_t nmemb, size_t size, // freestanding compare-pred* compar); void qsort(void* base, size_t nmemb, size_t size, c-compare-pred* compar); // freestanding void qsort(void* base, size_t nmemb, size_t size, compare-pred* compar); // freestanding // [c.math.rand], low-quality random number generation int rand(); void srand(unsigned int seed); // [c.math.abs], absolute values constexpr int abs(int j); // freestanding constexpr long int abs(long int j); // freestanding constexpr long long int abs(long long int j); // freestanding constexpr floating-point-type abs(floating-point-type j); // freestanding-deleted constexpr long int labs(long int j); // freestanding constexpr long long int llabs(long long int j); // freestanding constexpr div_t div(int numer, int denom); // freestanding constexpr ldiv_t div(long int numer, long int denom); // freestanding; see [library.c] constexpr lldiv_t div(long long int numer, long long int denom); // freestanding; see [library.c] constexpr ldiv_t ldiv(long int numer, long int denom); // freestanding constexpr lldiv_t lldiv(long long int numer, long long int denom); // freestanding }
The contents and meaning of the header <cstdlib> are the same as the C standard library header <stdlib.h>, except that it does not declare the type wchar_t, and except as noted in [support.types.nullptr], [support.types.layout], [support.start.term], [c.malloc], [c.mb.wcs], [alg.c.library], [c.math.rand], and [c.math.abs].
[Note 1: 
Several functions have additional overloads in this document, but they have the same behavior as in the C standard library.
— end note]
See also: ISO/IEC 9899:2018, 7.22

17.2.3 Null pointers [support.types.nullptr]

The type nullptr_t is a synonym for the type of a nullptr expression, and it has the characteristics described in [basic.fundamental] and [conv.ptr].
[Note 1: 
Although nullptr's address cannot be taken, the address of another nullptr_t object that is an lvalue can be taken.
— end note]
The macro NULL is an implementation-defined null pointer constant.163
See also: ISO/IEC 9899:2018, 7.19
163)163)
Possible definitions include 0 and 0L, but not (void*)0.

17.2.4 Sizes, alignments, and offsets [support.types.layout]

The macro offsetof(type, member-designator) has the same semantics as the corresponding macro in the C standard library header <stddef.h>, but accepts a restricted set of type arguments in this document.
Use of the offsetof macro with a type other than a standard-layout class ([class.prop]) is conditionally-supported.164
The expression offsetof(type, member-designator) is never type-dependent and it is value-dependent if and only if type is dependent.
The result of applying the offsetof macro to a static data member or a function member is undefined.
No operation invoked by the offsetof macro shall throw an exception and noexcept(offsetof(type, member-designator)) shall be true.
The type ptrdiff_t is an implementation-defined signed integer type that can hold the difference of two subscripts in an array object, as described in [expr.add].
The type size_t is an implementation-defined unsigned integer type that is large enough to contain the size in bytes of any object ([expr.sizeof]).
Recommended practice: An implementation should choose types for ptrdiff_t and size_t whose integer conversion ranks ([conv.rank]) are no greater than that of signed long int unless a larger size is necessary to contain all the possible values.
The type max_align_t is a trivial standard-layout type whose alignment requirement is at least as great as that of every scalar type, and whose alignment requirement is supported in every context ([basic.align]).
See also: ISO/IEC 9899:2018, 7.19
164)164)
Note that offsetof is required to work as specified even if unary operator& is overloaded for any of the types involved.

17.2.5 byte type operations [support.types.byteops]

template<class IntType> constexpr byte& operator<<=(byte& b, IntType shift) noexcept;
Constraints: is_integral_v<IntType> is true.
Effects: Equivalent to: return b = b << shift;
template<class IntType> constexpr byte operator<<(byte b, IntType shift) noexcept;
Constraints: is_integral_v<IntType> is true.
Effects: Equivalent to: return static_cast<byte>(static_cast<unsigned int>(b) << shift);
template<class IntType> constexpr byte& operator>>=(byte& b, IntType shift) noexcept;
Constraints: is_integral_v<IntType> is true.
Effects: Equivalent to: return b = b >> shift;
template<class IntType> constexpr byte operator>>(byte b, IntType shift) noexcept;
Constraints: is_integral_v<IntType> is true.
Effects: Equivalent to: return static_cast<byte>(static_cast<unsigned int>(b) >> shift);
constexpr byte& operator|=(byte& l, byte r) noexcept;
Effects: Equivalent to: return l = l | r;
constexpr byte operator|(byte l, byte r) noexcept;
Effects: Equivalent to: return static_cast<byte>(static_cast<unsigned int>(l) | static_cast<unsigned int>(r));
constexpr byte& operator&=(byte& l, byte r) noexcept;
Effects: Equivalent to: return l = l & r;
constexpr byte operator&(byte l, byte r) noexcept;
Effects: Equivalent to: return static_cast<byte>(static_cast<unsigned int>(l) & static_cast<unsigned int>(r));
constexpr byte& operator^=(byte& l, byte r) noexcept;
Effects: Equivalent to: return l = l ^ r;
constexpr byte operator^(byte l, byte r) noexcept;
Effects: Equivalent to: return static_cast<byte>(static_cast<unsigned int>(l) ^ static_cast<unsigned int>(r));
constexpr byte operator~(byte b) noexcept;
Effects: Equivalent to: return static_cast<byte>(~static_cast<unsigned int>(b));
template<class IntType> constexpr IntType to_integer(byte b) noexcept;
Constraints: is_integral_v<IntType> is true.
Effects: Equivalent to: return static_cast<IntType>(b);