Overview
The bottom of the type hierarchy consists of simple types. This comprises the primitive types that all other types are either based off of or derived from.
Signed | Unsigned | 32-bit | 64-bit |
---|---|---|---|
- | bool | 1 | 1 |
signed char | unsigned char | 1 | 1 |
short | unsigned short | 2 | 2 |
int | unsigned | 4 | 4 |
long | unsigned long | 4 | 8 |
long long | unsigned long long | 8 | 8 |
Real | Complex | 32-bit | 64-bit |
---|---|---|---|
float | - | 4 | 4 |
double | - | 8 | 8 |
long double | - | - | - |
- | float complex | 4 | 4 |
- | double complex | 8 | 8 |
- | long double complex | - | - |
Integers
Narrow types cannot be used directly in arithmetic. Instead they are first promoted to a wider type. On almost every system, this promotion will be to a signed int
of the same value, regardless of the signedness of the narrow type itself.
Character Types
The three types char
, signed char
, and unsigned char
are collectively called the character types. The implementation defines char
to have the same range, representation, and behavior as either signed char
or unsigned char
, but is considered incompatible with both. That is, it is a distinct type in the eyes of the type system.
Unsigned Integers
Name | Narrow | Rank | Minimum Width |
---|---|---|---|
bool | Yes | 0 | 1 |
char (maybe) | Yes | 1 | - |
unsigned char | Yes | 1 | 8 |
unsighed short | Yes | 2 | 16 |
unsigned int | No | 3 | 16 |
unsigned long | No | 4 | 32 |
unsigned long long | No | 5 | 64 |
Signed Integers
Name | Narrow | Rank | Minimum Width |
---|---|---|---|
char (maybe) | Yes | 1 | - |
signed char | Yes | 1 | 8 |
signed short | Yes | 2 | 16 |
signed int | No | 3 | 16 |
signed long | No | 4 | 32 |
signed long long | No | 5 | 64 |
float | - | - | - |
double | - | - | - |
long double | - | - | - |
Literals
Negative integer literals are typed in a counterintuitive way. When the compiler sees a number of form -X
, the type of X
is determined before being negated. Promotion follows the first fit rule described as follows:
Decimal | Oct/Hex |
---|---|
int | int |
long | unsigned |
long long | long |
- | unsigned long |
- | long long |
- | unsigned long long |
Integer constants can be made a certain signedness or type by using the following suffixes:
Suffix | Type |
---|---|
U | unsigned |
L | long |
LL | long long |
ULL | unsigned long long |
Integer Constant Expressions
An integer constant expression (ICE) is a compile-time integer value. Its value must be determinable at compile time (e.g. no function calls are permitted), and also no evaluation of an object must participate as an operand.
Floating Point
Literals
Floating-point constants can be made a certain type by using the following suffixes:
Suffix | Type |
---|---|
F | float |
L | long double |
Exact-Width Integer Types
The stdint.h
library contains exact-width integer types. These are aliases to types that represent an exact width and sign representation:
- If the type
uintN_t
is provided, it is an unsigned integer type with exactly bits of width and precision. - If the type
intN_t
is provided, is is signed, with two’s complement representation, has a width of exactly bits and a precision of .
The C standard says these typedef
s must be defined if they can be satisfied. Otherwise they may not exist.
Enumerated Types
An enum
is a mapping of identifiers with integer values. They have general form:
Bibliography
- “ISO: Programming Languages - C17,” April 2017, https://www.open-std.org/jtc1/sc22/wg14/www/abq/c17_updated_proposed_fdis.pdf.
- Jens Gustedt, Modern C (Shelter Island, NY: Manning Publications Co, 2020).
- Raymond, Eric. “The Lost Art of Structure Packing.” Accessed November 4, 2024. http://www.catb.org/esr/structure-packing/.
- Van der Linden, Peter. Expert C Programming: Deep C Secrets. Programming Languages / C. Mountain View, Cal.: SunSoft Pr, 1994.