Integer promotion is the implicit conversion of integer types with a conversion rank lower thanDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
int to either int or unsigned int before an operation is performed on them. This mechanism ensures that arithmetic and bitwise operations are executed at the CPU’s natural word size, aligning with the C standard’s execution model.
The Value Preservation Rule
The C standard dictates how these smaller types are promoted based on a concept called value preservation (C11 Standard, Section 6.3.1.1):- If an
intcan represent all possible values of the original type, the value is promoted toint. - If an
intcannot represent all possible values of the original type, the value is promoted tounsigned int.
int is typically 32 bits and types like char (8 bits) and short (16 bits) are smaller, they almost universally promote to a signed int, regardless of whether the original type was signed or unsigned.
Affected Types
Integer promotion applies specifically to types with an integer conversion rank lesser than the rank ofint:
char,signed char,unsigned charshort,unsigned short_Bool(a fundamental unsigned integer type)- Integer bit-fields
- Enumeration types (
enum)
Triggering Contexts
Promotion occurs automatically when the affected types are used as:- Operands of unary operators:
+,-,~ - Operands of binary operators: Arithmetic (
+,-,*,/,%), bitwise (&,|,^,<<,>>), and relational (==,!=,<,>,<=,>=). - Arguments to variadic functions: When passed to functions with a variable number of arguments (e.g.,
...), smaller integer types undergo default argument promotions. - Controlling expression of a
switchstatement: The integer expression evaluated to determine the execution path explicitly undergoes integer promotion.
Syntax and Behavior Visualization
The following compilable program demonstrates how the type of an expression changes due to integer promotion, evaluated using thesizeof operator, and how promotion alters the behavior of bitwise operations on small unsigned types.
Distinction from Usual Arithmetic Conversions
Integer promotion is the first step in evaluating expressions. It strictly handles types smaller thanint. If an expression involves types equal to or larger than int (e.g., int and long, or int and float), a separate mechanism called the usual arithmetic conversions takes over to find a common type after integer promotions have already been applied to any smaller operands.
Master C with Deep Grasping Methodology!Learn More





