[futurebasic] Re: [FB] CFIndexRead using FSRef

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

From: Alain Pastor <apastor@...>
Date: Fri, 25 Jan 2008 23:55:08 +0100
Steve a crit :
> I am never sure when to use @ ^ # or nothing at all.


When you pass a structure as a parameter to a local function, FB passes 
its actual address onto the function. That's why the argument list in 
its declaration must specify that the function is expecting an address 
(a pointer), which is the case with the FSRef opaque structure in your code:

local fn CFReadXML( indexID as CFIndex, sRef as ^FSRef )

Note that there is a plethora of variants to write the same statement, 
including a few that use the @ symbol. Here the caret is equivalent to 
'pointer to'.

Personally, I prefer the following syntax for a couple of reasons:

local fn CFReadXML( indexID as CFIndex, sRef as .FSRef )

First, the dot translates to 'point' in French, which is close to 
pointer. Then, the variable type is highlighted in the editor window, 
reminding me that I have to deal with a pointer later in the body of the 

However, I don't know if FBtoC can handle all the possible variants of 
the syntax.

The problem arises when you need to send to a Toolbox function the 
structure (or more accurately its address) that the FB local fn has 

It is to know that when the program must pass a structure to the 
Toolbox, FB resolves its address and sends this address as a parameter. 
In that regards it acts quite the same than for local fns.

So, in your example:

url = fn CFURLCreateFromFSRef( 0, sRef )

FB will try to send the address of the local variable sRef. That address 
(if even it is one because it is likely a register) has no practical 
use, but, as previously stated, the content of the sRef variable holds 
the actual address of the structure of interest. Now, using the # symbol 
tells FB not to resolve the address of the variable sRef to pass onto 
the Toolbox function, but send directly its value instead.

url = fn CFURLCreateFromFSRef( 0, #sRef )

Had the FSRef variable (sRef) been defined inside your local fn (in that 
case letting FB retrieve its address would have been relevant), you 
would have written :

url = fn CFURLCreateFromFSRef( 0, sRef )

As to the @ symbol, many programmers (among the best I must add) use it 
as a reminder when calling Toolbox functions: it says that this 
parameter variable will have its value updated by the Toolbox function 
being called (besides that's why such a variable must have an address in 
memory and therefore cannot be located in a register). That symbol is 
optional in this case and I personally don't use that syntax by laziness.

Hoping someone will correct me, if I'm wrong.