![]() |
|
bug or missunderstood? - Printable Version +- Boriel Basic Forum (https://forum.boriel.com) +-- Forum: Compilers and Computer Languages (https://forum.boriel.com/forumdisplay.php?fid=12) +--- Forum: ZX Basic Compiler (https://forum.boriel.com/forumdisplay.php?fid=11) +---- Forum: Bug Reports (https://forum.boriel.com/forumdisplay.php?fid=15) +---- Thread: bug or missunderstood? (/showthread.php?tid=744) |
bug or missunderstood? - Haplo - 2016-10-27 Hello, if I run this program: Code: clsthe output in screen is: valor:50 valor:244 valor:10000 valor:244 valor:50 valor:500 This is a bug? Re: bug or missunderstood? - boriel - 2016-11-07 hock: This definitely looks like a bug. What compiler version are you using?? Re: bug or missunderstood? - Haplo - 2016-11-07 Hello, the version is 1.4.0-s1967 Re: bug or missunderstood? - boriel - 2016-11-07 Haplo Wrote:Hello, the version is 1.4.0-s1967Phew!! :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: clsSome 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: clsMost 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). Re: bug or missunderstood? - Haplo - 2016-11-08 Thanks, I just update to s1968 ![]() I thought that if I declare "valor" as uinteger previously, would be enough. I used to declare the variables according their range of values, but this behavior disconcert me. By now, I will change all the ubyte variables to uinteger, avoiding the problem by this way. Re: bug or missunderstood? - boriel - 2016-11-08 Haplo Wrote:Thanks, I just update to s1968The range of valor is ok. The range of the others is not. Ok. This is something we need to discuss. Maybe is better to use the standard behaviour. Basically, in ZXBasic a * b is expanded to Uinteger *after* the multiplication. Other compilers expands first. But this is more expensive... |