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 | - | - |
Characters
Type char
is special since it can be signed or unsigned depending on platform. Keep in mind regardless of its signedness, it is still considered a distinct type from both the unsigned char
and signed char
type.
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.
Unsigned
These correspond to nonnegative integer values.
Name | Narrow | Rank |
---|---|---|
bool | Yes | 0 |
char (maybe) | Yes | 1 |
unsigned char | Yes | 1 |
unsighed short | Yes | 2 |
unsigned int | No | 3 |
unsigned long | No | 4 |
unsigned long long | No | 5 |
Signed
These correspond to possibly negative integer values.
Name | Narrow | Rank |
---|---|---|
char (maybe) | Yes | 1 |
signed char | Yes | 1 |
signed short | Yes | 2 |
signed int | No | 3 |
signed long | No | 4 |
signed long long | No | 5 |
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 forced to be unsigned or to be a type with minimal width by using the following suffixes:
Suffix | Type |
---|---|
U | unsigned |
L | long |
LL | long long |
ULL | unsigned long long |
Floating Point
Literals
Floating-point constants can be forced to be a type with minimal width by using the following suffixes:
Suffix | Type |
---|---|
F | float |
L | long double |
Enumerated Types
An enum
is a mapping of identifiers with integer values. They have general form:
Bibliography
- “ISO: Programming Languages - C,” April 12, 2011, https://port70.net/~nsz/c/c11/n1570.pdf.
- Van der Linden, Peter. Expert C Programming: Deep C Secrets. Programming Languages / C. Mountain View, Cal.: SunSoft Pr, 1994.