Datasheet

STANDARD CONVERSIONS
Standard conversions are built in the mikroC PRO for AVR. These conversions are
performed automatically, whenever required in the program. They can also be
explicitly required by means of the typecast operator (refer to the Explicit Typecast-
ing).
The basic rule of automatic (implicit) conversion is that the operand of simpler type
is converted (promoted) to the type of more complex operand. Then, the type of the
result is that of more complex operand.
Arithmetic Conversions
When using arithmetic expression, such as a + b, where a and b are of different
arithmetic types, the mikroC PRO for AVR performs implicit type conversions before
the expression is evaluated. These standard conversions include promotions of
“lower” types to “higher” types in the interests of accuracy and consistency.
Assigning a signed character object (such as a variable) to an integral object results
in automatic sign extension. Objects of type signed char always use sign extension;
objects of type unsigned char always has its high byte set to zero when converted
to int.
Converting a longer integral type to a shorter type truncates the higher order bits
and leaves low-order bits unchanged. Converting a shorter integral type to a longer
type either sign-extends or zero-fills the extra bits of the new value, depending on
whether the shorter type is signed or unsigned, respectively.
Note: Conversion of floating point data into integral value (in assignments or via
explicit typecast) produces correct results only if the
float value does not exceed
the scope of destination integral type.
In details:
Here are the steps the mikroC PRO for AVR uses to convert the operands in an
arithmetic expression:
First, any small integral types are converted according to the following rules:
1. char converts to int
2. signed char converts to int, with the same value
3.
short converts to int, with the same value, sign-extended
4. unsigned short converts to int, with the same value, zero-filled
5. enum converts to int, with the same value
175
MIKROELEKTRONIKA - SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Language Reference
mikroC PRO for AVR
CHAPTER 5