Balancing


Many binary operators (i.e. operators which work on two operands), require the operands to be converted to a common type before the operation is performed. This common type is also the type of the result. For example if an int is added to a long int, the int is first converted to a long int. If an int is added to an unsigned int, the int is first converted to an unsigned int.

This process of arriving at a common type is known as balancing or, in the terminology of the ISO-C Standard, the usual arithmetic conversions. Usually the conversions involve one operand being converted to that of the other; but occasionally the type of both operands must be changed. Sometimes we refer to an operand being promoted to the type of the other; don't confuse this process with integral promotion.

Balancing is performed according to the following set of rules:

See the following table:

OPERANDS

SIGNED INT

UNSIGNED INT

SIGNED LONG

UNSIGNED LONG

FLOAT

DOUBLE

LONG DOUBLE

SIGNED INT

signed int

unsigned int

signed long

unsigned long

float

double

long double

UNSIGNED INT

unsigned int

unsigned int

long
unsigned long

unsigned long

float

double

long double

SIGNED LONG

signed long

long
unsigned long

signed long

unsigned long

float

double

long double

UNSIGNED LONG

unsigned long

unsigned long

unsigned long

unsigned long

float

double

long double

FLOAT

float

float

float

float

float

double

long double

DOUBLE

double

double

double

double

double

double

long double

LONG DOUBLE

long double

long double

long double

long double

long double

long double

long double

Index