[futurebasic] Re: [FB] parameters & more

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : December 1998 : Group Archive : Group : All Groups

From: Rick Brown <rbrown@...>
Date: Wed, 30 Dec 1998 21:27:46 -0600
Lucy wrote:
> Finally pinned it down to a simple typo:
>   temprgn&.rgnBbox.left% (one dot)
> by mistake for
>   temprgn&..rgnBbox.left% (two dots)
> No errors, it just didn't do anything. (Obvious disclaimer: no errors _visible
> to the naked eye_ --for all I know, it was overwriting a huge chunk of memory
> that the app happened not to be using just then.) But I'm curious-- does
> anyone know what FB or the compiled app _thought_ it was doing when it
> encountered that single dot?

You've probably heard before that a handle is a "pointer to a pointer." 
The variable temprgn& held a long-integer, which pointed to another long
integer, which in turn pointed to your Region structure.  I like to use
examples with real numbers to make this clear:  Let's say temprgn&
contains the number 26103944.  That's the region's handle, and it's also
the address where another long integer is stored:

  Address(es):  Contents
  ------------  --------
  26103944-47   18559236

That second long integer is the address of (the beginning of) your
region structure:

  Address(es):  Contents
  ------------  --------
  18559236 - ?  (the region)

The "double-dot" syntax tells FB that it needs to do a
"double-indirection" in order to find the region.  FB gets the address
in temprgn& (26103944), looks in that address to find another address
(18559236), and looks in that second address to find the region.

But if you use the "single-dot" syntax, FB uses "single-indirection" to
try to find that region.  In this case it looks in temprgn&, finds the
number 26103944, and thinks _that's_ the address where the region
structure is.  But since your region is _really_ at address 18559236, FB
will end up reading from and/or writing to the wrong address--and you
can count yourself lucky if your whole system doesn't crash in that
case.

The "double-dot" syntax is appropriate for handles because handles
always use "double-indirection" to get to their data blocks.  In cases
where your variable contains a pointer that points _directly_ to the
data block, you use the "single-dot" syntax.  And since FB is not clever
enough to know whether the number inside the variable is supposed to be
a handle or a pointer, the compiler doesn't complain either way.

- Rick