[futurebasic] Re: [FB] fn FD_FSSpecCreatePath not working everywhere?

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

From: Robert Purves <listrp@...>
Date: Sat, 7 Jan 2012 16:48:34 +1300
Domokos Vekas wrote:

> Is there a simple rule for when to use # ?

The rule is only moderately simple. It is however very silly, er, a lovable idiosyncrasy inherited from early versions of FB.

[1] Check the toolbox definition, in this case:
toolbox fn FD_FSSpecCreatePath( FSSpec *spec, CFStringRef *outPath ) = OSStatus

[2] If the parameter of interest has a '*', that parameter is marked by FBtoC as being pass-by-reference.

[3] When a function call is processed by FBtoC, simple variable arguments corresponding to pass-by-reference parameters have their address taken, as though you had prefixed the variable with '@'. Thus the two calls below would generate the same (in this case obviously wrong) C code:
   dim as ^FSSpec  fs
   fs = ...
   fn FD_FSSpecCreatePath( fs, ... )
   fn FD_FSSpecCreatePath( @fs, ... )

[4] The behaviour in [3] can be overridden by the prefix '#', which means 'I want this argument to be passed by value'.
   fn FD_FSSpecCreatePath( #fs,... )

Robert P.