User`s manual

mikroBASIC
- Basic Compiler for Microchip PIC microcontrollers
r = expression
Refer to chapter Assignment and Implicit Conversion for details.
When adding operands of the same type and assigning value to third operand,
incorrect value may be proceeded if the result exceeds range of declared data type.
Similar rules apply to other arithmetical operators.
For example, if a and b are bytes, and cc is word:
a = 56
b = 200
cc = 1000
a + b equals 1, because result type is assumed to be same as the operands' type
(byte).
Added to cc, we get 1001, instead of the expected 1256.
Solution is to simply instruct the compiler to evaluate expression as you explicitly
define. For example, you could explicitly cast the expression, like this:
word(a +
b + c)
. As result fits in word range, we will get 1256 as we wanted to.
For more details, refer to chapter Explicit Conversion.
Comparing variables and constants always produces the correct results regardless
of the operands' type.
mikroBASIC
making it simple...
71
page
MikroElektronika: Development tools - Books - Compilers
Note