ABL electronic PIC12 Personal Computer User Manual


 
Arithmetic Conversions
When you use an arithmetic expression, such as
a+b, where a and b are of differ-
ent arithmetic types, mikroC performs implicit type conversions before the expres-
sion 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 set the high byte 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.
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 unsigned int, with the same value, zero-filled
5. enum converts to int, with the same value
After this, any two values associated with an operator are either
int (including
the long and unsigned modifiers), or they are float (equivalent with double
and long double in mikroC).
1. If either operand is float, the other operand is converted to float
2. Otherwise, if either operand is unsigned long, the other operand is converted
to
unsigned long
3. Otherwise, if either operand is long, the other operand is converted to long
4. Otherwise, if either operand is unsigned, the other operand is converted to
unsigned
5. Otherwise, both operands are int
MikroElektronika:
Development
tools
-
Books
-
Compilers
83
page
mikroC
- C Compiler for Microchip PIC microcontrollers
mikroC
making it simple...