[support.types]

# 17 Language support library [[support]](./#support)

## 17.2 Common definitions [support.types]

### [17.2.1](#cstddef.syn) Header <cstddef> synopsis [[cstddef.syn]](cstddef.syn)

// all freestandingnamespace std {using [ptrdiff_t](#lib:ptrdiff_t "17.2.1 Header <cstddef> synopsis [cstddef.syn]") = *see below*; using [size_t](cstdio.syn#lib:size_t "31.13.1 Header <cstdio> synopsis [cstdio.syn]") = *see below*; using [max_align_t](#lib:max_align_t "17.2.4 Sizes, alignments, and offsets [support.types.layout]") = *see below*; using [nullptr_t](#lib:nullptr_t "17.2.3 Null pointers [support.types.nullptr]") = decltype(nullptr); enum class [byte](#lib:byte "17.2.1 Header <cstddef> synopsis [cstddef.syn]") : unsigned char {}; // [[support.types.byteops]](#byteops "17.2.5 byte type operations"), byte type operationstemplate<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](cstdio.syn#lib:NULL "31.13.1 Header <cstdio> synopsis [cstdio.syn]") *see below*#define [offsetof](diff.offsetof#lib:offsetof "C.8.5.2 Macro offsetof(type, member-designator) [diff.offsetof]")(P, D) *see below*

[1](#cstddef.syn-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L82)

The contents and meaning of the header <cstddef> are the same as
the C standard library header [<stddef.h>](support.c.headers.general#header:%3cstddef.h%3e "17.15.1 General [support.c.headers.general]"),
except that it does not declare the type wchar_t,
that it does not define the macro unreachable,
that it also declares the type byte and its associated operations ([[support.types.byteops]](#byteops "17.2.5 byte type operations")),
and as noted in[[support.types.nullptr]](#nullptr "17.2.3 Null pointers") and[[support.types.layout]](#layout "17.2.4 Sizes, alignments, and offsets")[.](#cstddef.syn-1.sentence-1)

See also: ISO/IEC 9899:2024, 7.22

### [17.2.2](#cstdlib.syn) Header <cstdlib> synopsis [[cstdlib.syn]](cstdlib.syn)

[ð](#header:%3ccstdlib%3e)

namespace std {using size_t = *see below*; // freestandingusing div_t = *see below*; // freestandingusing ldiv_t = *see below*; // freestandingusing lldiv_t = *see below*; // freestanding}#define [NULL](cstdio.syn#lib:NULL "31.13.1 Header <cstdio> synopsis [cstdio.syn]") *see below* // freestanding#define [EXIT_FAILURE](#lib:EXIT_FAILURE "17.2.2 Header <cstdlib> synopsis [cstdlib.syn]") *see below* // freestanding#define [EXIT_SUCCESS](#lib:EXIT_SUCCESS "17.2.2 Header <cstdlib> synopsis [cstdlib.syn]") *see below* // freestanding#define [RAND_MAX](#lib:RAND_MAX "17.2.2 Header <cstdlib> synopsis [cstdlib.syn]") *see below*#define [MB_CUR_MAX](#lib:MB_CUR_MAX "17.2.2 Header <cstdlib> synopsis [cstdlib.syn]") *see below*namespace std {// Exposition-only function type aliasesextern "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]](support.start.term "17.5 Startup and termination"), start and termination[[noreturn]] void abort() noexcept; // freestandingint atexit(*c-atexit-handler** func) noexcept; // freestandingint atexit(*atexit-handler** func) noexcept; // freestandingint at_quick_exit(*c-atexit-handler** func) noexcept; // freestandingint 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; // freestandingchar* [getenv](support.runtime.general#lib:getenv "17.14.1 General [support.runtime.general]")(const char* name); int system(const char* string); // [[c.malloc]](c.malloc "20.2.12 C library memory allocation"), C library memory allocationvoid* aligned_alloc(size_t alignment, size_t size); void* calloc(size_t nmemb, size_t size); void free(void* ptr); void free_sized(void* ptr, size_t size); void free_aligned_sized(void* ptr, size_t alignment, size_t size); void* malloc(size_t size); void* realloc(void* ptr, size_t size);
 size_t memalignment(const void* p); // freestandingdouble 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); int strfromd(char* s, size_t n, const char* format, double fp); int strfromf(char* s, size_t n, const char* format, float fp); int strfroml(char* s, size_t n, const char* format, long double fp); 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]](c.mb.wcs "28.7.5 Multibyte / wide string and character conversion functions"), multibyte / wide string and character conversion functionsint 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]](alg.c.library "26.13 C library algorithms"), C standard library algorithmsvoid* bsearch(const void* key, void* base, size_t nmemb, size_t size, // freestanding*c-compare-pred** compar); void* bsearch(const void* key, void* base, size_t nmemb, size_t size, // freestanding*compare-pred** compar); const void* bsearch(const void* key, const void* base, size_t nmemb, // freestanding size_t size, *c-compare-pred** compar); const void* bsearch(const void* key, const void* base, size_t nmemb, // freestanding size_t size, *compare-pred** compar); void qsort(void* base, size_t nmemb, size_t size, *c-compare-pred** compar); // freestandingvoid qsort(void* base, size_t nmemb, size_t size, *compare-pred** compar); // freestanding// [[c.math.rand]](c.math.rand "29.5.10 Low-quality random number generation"), low-quality random number generationint rand(); void srand(unsigned int seed); // [[c.math.abs]](c.math.abs "29.7.2 Absolute values"), absolute valuesconstexpr int abs(int j); // freestandingconstexpr long int abs(long int j); // freestandingconstexpr long long int abs(long long int j); // freestandingconstexpr *floating-point-type* abs(*floating-point-type* j); // freestanding-deletedconstexpr long int labs(long int j); // freestandingconstexpr long long int llabs(long long int j); // freestandingconstexpr div_t div(int numer, int denom); // freestandingconstexpr ldiv_t div(long int numer, long int denom); // freestanding; see [[library.c]](library.c "16.2 The C standard library")constexpr lldiv_t div(long long int numer, long long int denom); // freestanding; see [[library.c]](library.c "16.2 The C standard library")constexpr ldiv_t ldiv(long int numer, long int denom); // freestandingconstexpr lldiv_t lldiv(long long int numer, long long int denom); // freestanding}

[1](#cstdlib.syn-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L239)

The contents and meaning of the header [<cstdlib>](#header:%3ccstdlib%3e "17.2.2 Header <cstdlib> synopsis [cstdlib.syn]") are the same as
the C standard library header [<stdlib.h>](support.c.headers.general#header:%3cstdlib.h%3e "17.15.1 General [support.c.headers.general]"),
except that it does not declare the types wchar_t or once_flag,
and does not declare the function call_once,
and except as noted in[[support.types.nullptr]](#nullptr "17.2.3 Null pointers"),[[support.types.layout]](#layout "17.2.4 Sizes, alignments, and offsets"),[[support.start.term]](support.start.term "17.5 Startup and termination"),[[c.malloc]](c.malloc "20.2.12 C library memory allocation"),[[c.mb.wcs]](c.mb.wcs "28.7.5 Multibyte / wide string and character conversion functions"),[[alg.c.library]](alg.c.library "26.13 C library algorithms"),[[c.math.rand]](c.math.rand "29.5.10 Low-quality random number generation"), and[[c.math.abs]](c.math.abs "29.7.2 Absolute values")[.](#cstdlib.syn-1.sentence-1)

[*Note [1](#cstdlib.syn-note-1)*:

Several functions have additional overloads in this document,
but they have the same behavior as in the [C standard library](library.c "16.2 The C standard library [library.c]")[.](#cstdlib.syn-1.sentence-2)

â *end note*]

See also: ISO/IEC 9899:2024, 7.24

### [17.2.3](#nullptr) Null pointers [[support.types.nullptr]](support.types.nullptr)

[1](#nullptr-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L262)

The type nullptr_t is a synonym
for the type of a nullptr expression, and it
has the characteristics
described in [[basic.fundamental]](basic.fundamental "6.9.2 Fundamental types") and [[conv.ptr]](conv.ptr "7.3.12 Pointer conversions")[.](#nullptr-1.sentence-1)

[*Note [1](#nullptr-note-1)*:

Although nullptr's address cannot be taken, the address of anothernullptr_t object that is an lvalue can be taken[.](#nullptr-1.sentence-2)

â *end note*]

[2](#nullptr-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L273)

The macroNULL is an implementation-defined null pointer constant[.](#nullptr-2.sentence-1)[159](#footnote-159 "Possible definitions include 0 and 0L, but not (void*)0.")

See also: ISO/IEC 9899:2024, 7.22

[159)](#footnote-159)[159)](#footnoteref-159)

Possible definitions include0 and0L,
but not(void*)0[.](#footnote-159.sentence-1)

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

[1](#layout-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L291)

The macrooffsetof(*type*, *member-designator*) has the same semantics as the corresponding macro in
the C standard library header [<stddef.h>](support.c.headers.general#header:%3cstddef.h%3e "17.15.1 General [support.c.headers.general]"), but
accepts a restricted set of *type* arguments in this document[.](#layout-1.sentence-1)

Use of the offsetof macro with a *type* other than a standard-layout class ([[class.prop]](class.prop "11.2 Properties of classes"))
is conditionally-supported[.](#layout-1.sentence-2)[160](#footnote-160 "Note that offsetof is required to work as specified even if unary operator&amp; is overloaded for any of the types involved.")

The expression offsetof(*type*, *member-designator*) is never [type-dependent](temp.dep.expr "13.8.3.3 Type-dependent expressions [temp.dep.expr]") and it is[value-dependent](temp.dep.constexpr "13.8.3.4 Value-dependent expressions [temp.dep.constexpr]") if and only if *type* is
dependent[.](#layout-1.sentence-3)

The result of applying the offsetof macro to
a static data member or a function member is undefined[.](#layout-1.sentence-4)

No operation invoked by the offsetof macro shall throw an exception andnoexcept(offsetof(*type*, *member-designator*)) shall be true[.](#layout-1.sentence-5)

[2](#layout-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L316)

The type ptrdiff_t is animplementation-defined
signed integer type that can
hold the difference of two subscripts in an array object, as described in [[expr.add]](expr.add "7.6.6 Additive operators")[.](#layout-2.sentence-1)

[3](#layout-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L322)

The type size_t is animplementation-defined
unsigned integer type that is large enough
to contain the size in bytes of any object ([[expr.sizeof]](expr.sizeof "7.6.2.5 Sizeof"))[.](#layout-3.sentence-1)

[4](#layout-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L328)

*Recommended practice*: An implementation should choose types for ptrdiff_t and size_t whose integer conversion ranks ([[conv.rank]](conv.rank "6.9.6 Conversion ranks")) are no greater than that ofsigned long int unless a larger size is necessary to contain all the possible values[.](#layout-4.sentence-1)

[5](#layout-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L334)

The typemax_align_t is a trivially copyable 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]](basic.align "6.8.3 Alignment"))[.](#layout-5.sentence-1)

std​::​is_trivially_default_constructible_v<max_align_t> is true[.](#layout-5.sentence-2)

See also: ISO/IEC 9899:2024, 7.22

[160)](#footnote-160)[160)](#footnoteref-160)

Note that offsetof is required to work as specified even if unaryoperator& is overloaded for any of the types involved[.](#footnote-160.sentence-1)

### [17.2.5](#byteops) byte type operations [[support.types.byteops]](support.types.byteops)

[ð](#lib:operator%3c%3c=,byte)

`template<class IntType>
  constexpr byte& operator<<=(byte& b, IntType shift) noexcept;
`

[1](#byteops-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L353)

*Constraints*: is_integral_v<IntType> is true[.](#byteops-1.sentence-1)

[2](#byteops-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L357)

*Effects*: Equivalent to:return b = b << shift;

[ð](#lib:operator%3c%3c,byte)

`template<class IntType>
  constexpr byte operator<<(byte b, IntType shift) noexcept;
`

[3](#byteops-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L370)

*Constraints*: is_integral_v<IntType> is true[.](#byteops-3.sentence-1)

[4](#byteops-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L374)

*Effects*: Equivalent to:return static_cast<byte>(static_cast<unsigned int>(b) << shift);

[ð](#lib:operator%3e%3e=,byte)

`template<class IntType>
  constexpr byte& operator>>=(byte& b, IntType shift) noexcept;
`

[5](#byteops-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L389)

*Constraints*: is_integral_v<IntType> is true[.](#byteops-5.sentence-1)

[6](#byteops-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L393)

*Effects*: Equivalent to:return b = b >> shift;

[ð](#lib:operator%3e%3e,byte)

`template<class IntType>
  constexpr byte operator>>(byte b, IntType shift) noexcept;
`

[7](#byteops-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L406)

*Constraints*: is_integral_v<IntType> is true[.](#byteops-7.sentence-1)

[8](#byteops-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L410)

*Effects*: Equivalent to:return static_cast<byte>(static_cast<unsigned int>(b) >> shift);

[ð](#lib:operator%7c=,byte)

`constexpr byte& operator|=(byte& l, byte r) noexcept;
`

[9](#byteops-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L424)

*Effects*: Equivalent to: return l = l | r;

[ð](#lib:operator%7c,byte)

`constexpr byte operator|(byte l, byte r) noexcept;
`

[10](#byteops-10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L435)

*Effects*: Equivalent to:return static_cast<byte>(static_cast<unsigned int>(l) | static_cast<unsigned int>(r));

[ð](#lib:operator&=,byte)

`constexpr byte& operator&=(byte& l, byte r) noexcept;
`

[11](#byteops-11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L449)

*Effects*: Equivalent to: return l = l & r;

[ð](#lib:operator&,byte)

`constexpr byte operator&(byte l, byte r) noexcept;
`

[12](#byteops-12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L460)

*Effects*: Equivalent to:return static_cast<byte>(static_cast<unsigned int>(l) & static_cast<unsigned int>(r));

[ð](#lib:operator%5e=,byte)

`constexpr byte& operator^=(byte& l, byte r) noexcept;
`

[13](#byteops-13)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L474)

*Effects*: Equivalent to: return l = l ^ r;

[ð](#lib:operator%5e,byte)

`constexpr byte operator^(byte l, byte r) noexcept;
`

[14](#byteops-14)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L485)

*Effects*: Equivalent to:return static_cast<byte>(static_cast<unsigned int>(l) ^ static_cast<unsigned int>(r));

[ð](#lib:operator~,byte)

`constexpr byte operator~(byte b) noexcept;
`

[15](#byteops-15)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L499)

*Effects*: Equivalent to:return static_cast<byte>(~static_cast<unsigned int>(b));

[ð](#lib:to_integer,byte)

`template<class IntType>
  constexpr IntType to_integer(byte b) noexcept;
`

[16](#byteops-16)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L514)

*Constraints*: is_integral_v<IntType> is true[.](#byteops-16.sentence-1)

[17](#byteops-17)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L518)

*Effects*: Equivalent to: return static_cast<IntType>(b);
