C language compiler

Implicit conversions

When constants and variables of different types are mixed in the same expression, C compiler will convert them to the same type automatically (``implicit conversion'') unless they are already casted to the same type. The following topics contain more details about implicit conversions:

Characters and integers

Any of the following may be used in an expression where an int or unsigned int may be used.

If an int can represent all values of the original type, the value is converted to an int; otherwise it is converted to an unsigned int. This process is called integral promotion.

Compilation mode dependencies that affect unsigned types

Signed and unsigned integers

Integral and floating

When a floating type is converted to any integral type, any fractional part is discarded.

Float and double

A float is promoted to double or long double, or a double is promoted to long double without a change in value.

The actual rounding behavior that is used when a floating point value is converted to a smaller floating point value depends on the rounding mode in effect at the time of execution. The default rounding mode is ``round to nearest.'' See ``Floating Point Operations'' and the IEEE Standard for Binary Floating-Point Arithmetic (ANSI/IEEE Std 754-1985) for a more complete discussion of rounding modes.

Usual arithmetic conversions

Some binary operators convert the types of their operands in order to yield a common type, which is also the type of the result. These are called the usual arithmetic conversions:

Next topic: Expressions
Previous topic: Conversions and expressions

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003