07-27-2012, 12:14 PM
boriel Wrote:Hmmm. I'm afraid not. This is a feature, the same way as in C, due to truncation. c1 is always uByte and you can't gues in compile time it's value, so there might be a chance that, effectively, c1 * 9 > 255. C does the same. What you get is (PEEK(x) * 9 bAND 0xFFh)
We already discussed this. It's not the same way as C. In fact, C does the calculation correctly. In both z88dk and gcc, this program:
Code:
#include <stdio.h>
int main (void) {
unsigned char c = 255; // This will have to do for PEEK 3 ;-)
printf ("%d * 3 = %d\n", c, c * 9);
return 0;
}
Outputs
Code:
255 * 3 = 2295
I still find zxb behaviour quite confusing regarding the lack of type promotion. I shouldn't have to typecast this:
Code:
Dim numAttrs as uInteger
Dim numLines as uByte
...
numAttrs = 32 * numLines
as I don't have to do it in either freeBasic or C... But in ZX Basic I have to explicitly typecast numLines to uInteger for it to work correctly, which I find quite awkward.