Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Line of sight
#14
na_th_an Wrote:While you are at it, you should try to solve the type casting of some expressions... This should work:

Code:
Dim lsb, msb as uByte
Dim address as uInteger

...

address = lsb + (msb << 8)
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.
Are you sure C does not behave this way? I mean msb (as char) << 8 should be 0 in C also.
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:

Code:
Dim x, cx as uByte
Dim dx uInteger

...

dx = x - cx
dx is always positive, as x and cx are unsigned... But the results should be considered signed integer, and not unsigned char.
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.
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.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)