Mikroelektronika MIKROE-742 데이터 시트

다운로드
페이지 532
TYPES CONVERSIONS
Conversion of variable of one type to a variable of another type is typecasting. mikroPas-
cal PRO for AVR supports both implicit and explicit conversions for built-in types.
Implicit Conversion
Compiler will provide an automatic implicit conversion in the following situations:
- statement requires an expression of particular type (according to language defini
tion), and we use an expression of different type, 
- operator requires an operand of particular type, and we use an operand of differ
ent type, 
- function requires a formal parameter of particular type, and we pass it an object of  
different type, 
- result does not match the declared function return type. 
Promotion
When operands are of different types, implicit conversion promotes the less com-
plex type to more complex type taking the following steps:
byte/char

word
short   

integer
short  

longint
integer

longint
integer 

real
Higher bytes of extended unsigned operand are filled with zeroes. Higher bytes of
extended signed operand are filled with bit sign (if number is negative, fill higher
bytes with one, otherwise with zeroes). For example:
var a : byte; b : word;
...
a := $FF;
b := a;  // a is promoted to word, b becomes $00FF
Clipping
In assignments and statements that require an expression of particular type, desti-
nation will store the correct value only if it can properly represent the result of
expression, i.e. if the result fits in destination range.
If expression evaluates to a more complex type than expected, excess of data will
be simply clipped (higher bytes are lost).
153
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Language Reference
mikroPASCAL PRO for AVR
CHAPTER 5