Mikroelektronika MIKROE-724 データシート

ページ / 726
214
mikoBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
Types Conversions
Conversion of variable of one type to a variable of another type is typecasting. mikroBasic PRO for dsPIC30/33 and 
PIC24 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 complex type to more complex type taking 
the following steps:
bit       →  byte/char
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 a as byte
dim b as 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, destination 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).
dim i as byte
dim j as word
‘...
j = $FF0F
i = j  ‘ i becomes $0F, higher byte $FF is lost