Mikroelektronika MIKROE-350 Fiche De Données

Page de 526
TYPES CONVERSIONS
Conversion of variable of one type to variable of another type is typecasting.
mikroBasic 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 
definition) and we use an expression of different type, 
- operator requires an operand of particular type and we use an operand of 
different 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 to the more complex type taking the following steps:
byte/char 

word
short     

integer
short     

longint
integer   

longint
integral  

float
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:
dim as byte
dim 
as word
'...
a = $FF
b = a  ' a is promoted to word, b becomes $00FF
143
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Language Reference
mikroBasic PRO for AVR
CHAPTER 5