Conditional NOT
Chris (121) 472 posts |
I’ve run into something that’s puzzling me. I have a simple function that does some bounds checking on a heap block before trying to read a value from it:
The function returns 0 if there’s an attempted read from outside the block’s bounds, otherwise it updates
The problem is that this calls
Have I misunderstood the use of |
Frank de Bruijn (160) 228 posts |
That’s because NOT 1 isn’t 0. It’s -2. You need to make the function return either 0 (FALSE) or -1 (TRUE). |
Steve Fryatt (216) 2103 posts |
Yes, you have. BBC BASIC’s “boolean” operators are not boolean: they’re bitwise. Conditional statements like Because You have to be very careful when doing boolean logic in BBC BASIC. Unless you know that all of the inputs will always evaluate to
in BBC BASIC. In C, it’s not unusual to see
because the
(with the bitwise |
Chris (121) 472 posts |
Thanks both – that’s very helpful. |