Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
bug or missunderstood?
#4
Haplo Wrote:Hello, the version is 1.4.0-s1967
Phew!! :roll:
It's not a bug (BTW the latest version is 1.4.0-s1968).

The problem is you are declaring a and b as ubyte, and ZX Basic does not typecast by default to Uinteger if the result is uinteger.
Your code:
Code:
cls
dim a,b as ubyte
dim dw1,dw2 as uinteger
b=5
a=100
valor=a*b
declares A and B as Ubyte. You should declare at least one of them as UInteger or use an explicit CAST.
Some compilers (e.g. most C Compilers) detects that 'valor' is Uinteger and will typecast A and B to Uinteger.
ZX Basic does not, for performance reasons (Z80 and 48k are so tiny... :roll: )
You can overcome this by doing an Explicit CAST. Try this:
Code:
cls
dim a,b as ubyte
dim dw1,dw2 as uinteger
b=5
a=100
valor=CAST(Uinteger, a) * b : REM Explicit CAST of a (or b) will convert all the expression to Uinteger
When using CAST( ), the expression (a) is converted ('casted') to UInteger. The compiler realizes that b is also Ubyte and "promotes" b also to Uinteger and peforms the multiplication.
Most C compilers do that automatically. ZXBasic needs you to explicit use CAST in one of the operands.
I'm thinking whether or not ZX Basic should follow the policy of the other compilers, but this will reduce performance (and take more memory).
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)