Conditional NOT
|
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 |
|
That’s because NOT 1 isn’t 0. It’s -2. You need to make the function return either 0 (FALSE) or -1 (TRUE). |
|
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 |
|
Thanks both – that’s very helpful. |