[futurebasic] Re: [FB] BITTST

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : May 1999 : Group Archive : Group : All Groups

From: Rick Brown <rbrown@...>
Date: Fri, 21 May 1999 21:27:39 -0500

Steven J. Stratford wrote:

> Shouldn't this give 0 1 0 0 0 0 0 1? ("A"=65=01000001)
>
> tmp$="A"
> a& = @tmp$+1
> for i& = 0 to 7
>   PRINT FN BITTST(a&,i&);
> next i&
>
> Keeps giving me 0 0 0 0 0 0 1 0
> --Steve

This is one of those peculiar FB implementations of a Toolbox function.  In
BITTST (and many other Toolbox routines), the OS wants the parameter to be the
_address_ of a data structure, but FB wants the parameter to be the data
structure itself (in the form of a variable).  When you pass a variable (in
this case, "a&") to the function, FB then passes the _address_ of the variable
(essentially, "@a&") to the OS Toolbox.

Internally, when BITTST gets an address, it looks at the bits of whatever is
located at that address.  This means that FB's BITTST(a&, i&) will return a
bit in the variable a& (not a bit in tmp$).

To tell FB, "No, no, I don't want you to pass the _address_ of a&; I want you
to pass the _contents_ of a&," you put a "#" in front of the expression:

  BITTST(#a&, i&)

Since the contents of a& is a pointer to the first byte pass the beginning of
tmp$, the above gets you what you want.

In a nutshell: for certain (not all!) FB Toolbox implementations:

  TheToolboxRoutine(var,...)     -> FB passes the address of var to the
Toolbox
  TheToolboxRoutine(#longExpr,...)   -> FB passes longExpr to the Toolbox

Hope this helps.
- Rick