Oracle® Solaris Studio 12.4: C User's Guide

Exit Print View

Updated: March 2015
 
 

2.6.2 Usual Arithmetic Conversions

Some binary operators convert the types of their operands to yield a common type, which is also the type of the result. These conversions are called the usual arithmetic conversions. For -std=c11 the usual arithmetic conversions are defined in the 9899:2011 ISO/IEC C Programming Language standard. For -std=c99 the usual arithmetic conversions are defined in the 9899:1999 ISO/IEC C Programming Language standard. For -std=c89 -pedantic the usual arithmetic conversions are defined in the 9899:1990 ISO/IEC C Programming Language. For -std=c89 -pedantic=no and -Xs flags the usual arithmetic conversions are defined as follows:

  • If either operand is type long double, the other operand is converted to long double.

  • Otherwise, if either operand has type double, the other operand is converted to double.

  • Otherwise, if either operand has type float, the other operand is converted to float.

  • Otherwise, the integral promotions are performed on both operands. Then, these rules are applied:

    • If either operand has type unsigned long long int, the other operator is converted to unsigned long long int.

    • If either operand has type long long int, the other operator is converted to long long int.

    • If either operand has type unsigned long int, the other operand is converted to unsigned long int.

    • Otherwise, when you compile with –m64, if one operand has type long int and the other has type unsigned int, both operands are converted to unsigned long int.

    • Otherwise, if either operand has type long int, the other operand is converted to long int.

    • Otherwise, if either operand has type unsigned int, the other operand is converted to unsigned int.

    • Otherwise, both operands have type int.