02-29-2012, 01:49 PM
na_th_an Wrote:While you are at it, you should try to solve the type casting of some expressions... This should work:Are you sure C does not behave this way? I mean msb (as char) << 8 should be 0 in C also.
But it doesn't, as it tries to shoft msb left 8 times but using 8 bits, so it always equals 0. You have to define msb as uInteger for it to work correctly.Code:Dim lsb, msb as uByte
Dim address as uInteger
...
address = lsb + (msb << 8)
Anyway, you can enforce typecast explicitly, using CAST:
Code:
Dim lsb, msb as uByte
Dim address as uInteger
...
address = lsb + CAST(Uinteger, msb) << 8
na_th_an Wrote:In the same fashion:I need an example in other languajes (ej. C), because as far as I know, dx variable is positive only if x is ALWAYS >= cx. I will use CAST(Uinteger, x) to avoid this problem.
dx is always positive, as x and cx are unsigned... But the results should be considered signed integer, and not unsigned char.Code:Dim x, cx as uByte
Dim dx uInteger
...
dx = x - cx
I find this to be the biggest problem with the compiler. No other language that I know behaves that way, and it forces you to find dirty walkarounds.