mikroC
making it simple...
Arithmetic Conversions
mikroC - C Compiler for Microchip PIC microcontrollers
When you use an arithmetic expression, such as a+b, where a and b are of different arithmetic types, mikroC 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 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
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,
4.unsigned short converts to unsigned int, with the same value,
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
|
| page |
MikroElektronika: Development tools - Books - Compilers | 83 | |
|