[futurebasic] the merits of reading the docs! -> heartache avoidance

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : August 2001 : Group Archive : Group : All Groups

From: jonathan <jonnnathan@...>
Date: Sat, 18 Aug 2001 22:39:19 +0200
i decided to read the docs. y'know, accidents do happen.
anyway i stumbled on the following.

> Registers are long integer containers. If you place a word-sized
> integer or a byte in a register, it is treated as a long integer.
> This may not always be what you intended when signed values are
> expected. For instance, a signed byte has a range of 0-128.
> After 128, the number wraps into negative values in the
> range of -127 to -1. If a register is used for a signed byte
> variable, its range becomes 0-255 instead of -127 to +128.
> In other words, the positive or negative sign of the number will be lost.

Well a few weeks back i was debugging a variable [DIMMED AS INT] that kept
changing its value, and I couldn't understand why. I even did tests on
putting in a value and then extracting it. It changed.

On reading the above [from Editor doc -> Preferences], i now understand why
and i will be clearly fine-toothcombing my code to use UNSIGNED INT [OR
UNSIGNED BYTE] where i can, and then refusing to let signed variables get
put in the registers, using '@'. Then i can optimise speed and keep
accuracy. i'd advise everyone to read this chapter carefully and avoid my
mistakes.

:-j