cpp/language/types

Void type

 * - type with an empty set of values. It is an that cannot be completed (consequently, objects of type  are disallowed). There are no s of, nor s to . However,  and s returning type  (procedures in other languages) are permitted.

std
std is the type of the null pointer literal,. It is a distinct type that is not itself a pointer type or a pointer to member type. Its values are null pointer constant (see null), and may be to any pointer and pointer to member type.

is equal to.

Data models
The choices made by each implementation about the sizes of the fundamental types are collectively known as data model. Four data models found wide acceptance:

32 bit systems:
 * LP32 or 2/4/4 ( is 16-bit, and pointer are 32-bit)
 * Win16 API
 * ILP32 or 4/4/4 (,, and pointer are 32-bit);
 * Win32 API
 * Unix and Unix-like systems (Linux, macOS)

64 bit systems:
 * LLP64 or 4/4/8 ( and are 32-bit, pointer is 64-bit)
 * Win32 API (also called the Windows API) with compilation target (AArch64) or  (a.k.a. x64)
 * LP64 or 4/8/8 ( is 32-bit, and pointer are 64-bit)
 * Unix and Unix-like systems (Linux, macOS)

Other models are very rare. For example, ILP64 (8/8/8:, , and pointer are 64-bit) only appeared in some early 64-bit Unix systems (e.g. ).

Standard integer types

 * - basic integer type. The keyword may be omitted if any of the modifiers listed below are used. If no length modifiers are present, it's guaranteed to have a width of at least 16 bits. However, on 32/64 bit systems it is almost exclusively guaranteed to have width of at least 32 bits (see below).

Modifiers
Modifies the basic integer type. Can be mixed in any order. Only one of each group can be present in type name.


 * Signedness:
 * - target type will have signed representation (this is the default if omitted)
 * - target type will have unsigned representation


 * Size:
 * - target type will be optimized for space and will have width of at least 16 bits.
 * - target type will have width of at least 32 bits.

Note: as with all type specifiers, any order is permitted: and  name the same type.

Properties
The following table summarizes all available integer types and their properties in various common data models:

Note: integer arithmetic is defined differently for the signed and unsigned integer types. See, in particular.

std is the unsigned integer type of the result of the operator.

Extended integer types
The extended integer types are implementation-defined. Note that fixed width integer types are typically aliases of the standard integer types.

Boolean type

 * - type, capable of holding one of the two values: or . The value of  is implementation defined and might differ from 1.

Character types

 * - type for signed character representation.
 * - type for unsigned character representation. Also used to inspect (raw memory).
 * - type for character representation which can be most efficiently processed on the target system (has the same representation and alignment as either or, but is always a distinct type). Multibyte characters strings use this type to represent code units.  The signedness of  depends on the compiler and the target platform: the defaults for ARM and PowerPC are typically unsigned, the defaults for x86 and x64 are typically signed.
 * - type for wide character representation (see wide strings). It has the same size, signedness, and alignment as one of the integer types, but is a distinct type. In practice, it is 32 bits and holds UTF-32 on Linux and many other non-Windows systems, but 16 bits and holds UTF-16 code units on Windows. The standard used to require to be large enough to represent any supported character code point. However, such requirement cannot be fulfilled on Windows, and thus it is considered as a defect and removed.

Besides the minimal bit counts, the C++ Standard guarantees that
 * == &le;  &le;  &le;  &le;.

Note: this allows the extreme case in which are sized 64 bits, all types (including ) are 64 bits wide, and  returns 1 for every type.

Standard floating-point types
The following three types and their cv-qualified versions are collectively called standard floating-point types.


 * - single precision floating-point type. Matches if supported.
 * - double precision floating-point type. Matches if supported.
 * - extended precision floating-point type. Matches if supported, otherwise matches  if supported, otherwise matches some non-IEEE-754 extended floating-point format as long as its precision is better than binary64 and range is at least as good as binary64, otherwise matches IEEE-754 binary64 format.
 * binary128 format is used by some HP-UX, SPARC, MIPS, ARM64, and z/OS implementations.
 * The most well known IEEE-754 binary64-extended format is . It is used by many x86 and x86-64 implementations (a notable exception is MSVC, which implements in the same format as, i.e. binary64).

Extended floating-point types
The extended floating-point types are implementation-defined. They may include fixed width floating-point types.

Properties
Floating-point types may support special values:
 * infinity (positive and negative), see infinity
 * the negative zero, . It compares equal to the positive zero, but is meaningful in some arithmetic operations, e.g., but ), and for some mathematical functions, e.g.
 * not-a-number (NaN), which does not compare equal with anything (including itself). Multiple bit patterns represent NaNs, see std, nan. Note that C++ takes no special notice of signalling NaNs other than detecting their support by std, and treats all NaNs as quiet.

Real floating-point numbers may be used with + - / * and various mathematical functions from. Both built-in operators and library functions may raise floating-point exceptions and set errno as described in.

Floating-point expressions may have greater range and precision than indicated by their types, see flt_eval_method. Floating-point expressions may also be contracted, that is, calculated as if all intermediate values have infinite range and precision, see. Standard C++ does not restrict the accuracy of floating-point operations.

Some operations on floating-point numbers are affected by and modify the state of the floating-point environment (most notably, the rounding direction).

are defined between real floating types and integer types.

See Limits of floating-point types and std for additional details, limits, and properties of the floating-point types.

Range of values
The following table provides a reference for the limits of common numeric representations.

Prior to C++20, the C++ Standard allowed any signed integer representation, and the minimum guaranteed range of N-bit signed integers was from to  (e.g. -127 to 127 for a signed 8-bit type), which corresponds to the limits of  or.

However, all C++ compilers use representation, and as of C++20, it is the only representation allowed by the standard, with the guaranteed range from  to  (e.g. -128 to 127 for a signed 8-bit type).

8-bit ones' complement and sign-and-magnitude representations for have been disallowed since C++11 (via the resolution of ), because a UTF-8 code unit of value 0x80 used in a  must be storable in a  type object.

Note: actual (as opposed to guaranteed minimal) limits on the values representable by these types are available in C numeric limits interface and std.

Keywords
,, , , , ,

,, , , , ,