Overview

Types in C are categorized corresponding to a hierarchy with a foundation comprising of the simple types. These types are then grouped and further categorized until we reach the top of the hierarchy consisting of all types.

All types are categorized as function types or object types. An object type is complete if there is sufficient information to determine the size of objects of that type. Otherwise we say it is incomplete.

Basic Types

The basic types comprise of char, the signed/unsigned integer types, and the floating point types. All basic types are complete object types.

Integer Types

The integer types comprise of char, the signed/unsigned integer types, and enums.

Arithmetic Types

Integer and floating point types are collectively called arithmetic types. Each arithmetic type belongs to one type domain: the real type domain comprises the real types and the complex type domain comprises the complex types.

Conversions

Several operators convert operand values from one type to another automatically.

The above quote refers to implicit conversions. Alternatively, we can use cast operations to perform explicit conversions.

Usual Arithmetic Conversions

As a general rule, the result of an operation has the type of the operand with wider range. The usual arithmetic conversions behave according to the following pattern:

  1. Determine a common real type for the operands and result.
  2. Convert each operand, without change of type domain, to a type with real type matching the common real type.
  3. Unless explicitly stated otherwise, the common real type is the corresponding real type of the result, whose type domain is that of the operands if they are the same and complex otherwise.

Common real types are prioritized in the following order:

  1. long double
  2. double
  3. float
  4. If both operands have the same signedness, the higher ranked type.
  5. If the unsigned operand has rank than that of the other, the unsigned type.
  6. If the signed operand’s includes that of the other, the signed type.
  7. The unsigned integer type corresponding to that of the signed integer type.

Bibliography

2 items under this folder.