[futurebasic] Re: [FB] Re: # in CALL syntax

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

From: Alain Pastor <apastor@...>
Date: Fri, 26 Jan 2001 01:52:43 +0100

lcs@... wrote:

> Salut encore Alain,
> Thanks for injecting some pertinant
> new considerations.  The relation of # to
> register variables is list floklore but
> absent from what you quoted...
> I confess I am more confused than ever.
> But that is often a necessary intermediate
> step to a new understanding.
> Laurent
> PS. For anyone rereading, please note the following
> typo of mine:
> x&=#[pictH&]+_picFrame
> which should have been:
> x&=[pictH&]+_picFrame
> PPS.  I cannot resist asking one question.
> Why is the use of # in the CALL syntax not also
> present in FN syntax?

re hello,

I'm sorry to make the thing more confusing. But, to your question, I would
hazard an answer: "It is not necessary."
When you send a value to a LOCAL FN (using a literal, an expression or a
variable name) it is copied somewhere (into a register if you have register on
or into a location in memory). In your code you refer to that value by a
symbolic name (the variable name used in the formal parameter list), the
Compiler always knows what you are talking about. It seems to me that there is
another level of indirection compared to the calling for a Toolbox procedure.
I've just tested this, and we can write something as crazy as the following:

local fn test (r as ptr to rect)
  print r.left,r.top,r.right,r.bottom
end fn

fn test(456489)

Imagine the damage I can do if I call a function that is supposed to affect
the so called rectangle.
I think it is something like the above that the # symbol allows for Toolbox
You can pass an arbitrary address with no reference to any variable known by
the Compiler.

You cannot write this for example:

call SetRect(456489, 0, 0, 0, 0)

The Compiler stops telling you it was expecting a variable (in order to send
its address to the Toolbox), however it accepts the following:

call SetRect(#456489, 0, 0, 0, 0)

The # syntax is useful when you need to calculate the address of specific data
in memory and alter or use them via a Toolbox call (the case of picFrame: you
know the starting address in memory and the offset for the data of interest,
adding the two gives the value you need).
Another use is to force a register variable to be used in a Toolbox call that
requires an address in memory for the variable. It speeds the things up
preventing you to move bytes around.
For instance with register on, this doesn't work:

local fn test (r as ptr to rect)
  call FrameRect(r)
end fn

but this works :

local fn test (r1 as ptr to rect)
  dim r2 as rect
  r2 = r1
  call FrameRect(r2)
end fn

and also this:

local fn test (r as ptr to rect)
  call FrameRect(#r)
end fn

I seem to vaguely recall that there are also some strange Toolbox calls that
require the use of the # symbol if you want to force a nil value for one of
their parameters.

Let me add that you must not take my words as rock solid, it is just how I
think the things work.
Anyone else is missing Rick's posts BTW?



FB^3 in Europe:  http://euro.futurebasic.com/
FB II Pouch:     http://www.pixmix.com/FB/outils.html