Numeric promotions are designed to promote narrow data types such as char, short, float etc. to wide data types such as int, double etc. Narrow data types use less bits and Wide data types use more bits.
For example,
char value{'a'};
int repr{value}; // promotion from 'char' to 'int'There is a bit of theory for such promotions. CPUs perform better with their native word size data types. For example, 32-bits CPUs can process data of size 32-bits efficiently than smaller size data. Thus, C++ performs implicit numeric promotions from narrower data types to wider data types.
Converting a narrow type to wide type that does not meet the goal mentioned above, does not come into the category of numeric promotions. For example, int to long, char to short, etc. This is because int to long conversion maybe from size 32-bits to 64-bits and CPU is 32-bits and so not useful. Conversion of these narrow data types to wider data types comes into numeric conversions category.
Advantages of Numerical Promotions
- Making processing efficient by promoting data size efficiently supported by CPUs.
- Removing redundancy of code. For example, a function with parameter
intcan be called with argument of typechar,short, etc. Otherwise, we would need to create different definitions of same function for different data types.