| xHarbour Reference Documentation > Operator Reference |
![]() |
![]() |
![]() |
Function-reference operator (unary): obtains a function pointer.
( @<funcName>() ) --> pFuncPointer
The function-reference operator retrieves the pointer to a function or procedure. The resulting value is of Valtype()=="P".
A function pointer can be used with function HB_Exec() or HB_ExecFromArray() to execute the function indirectly. This type of indirect execution is similar to using <funcName> within a macro-expression, or embedding the call within a code block which is then passed to the Eval() function. If a function is to be called indirectly for multiple times, however, the usage of the function-pointer along with HB_Exec() or HB_ExecFromArray() has a considerable performance advantage.
Note: The function-reference operator can resolve FUNCTIONs or PROCEDUREs declared as STATIC only if the referenced <funcName> is declared in the same PRG file where the operator is used. Pointers to methods of objects can only be obtained using function HB_ObjMsgPtr().
| See also: | {|| }, ( ), FUNCTION, HB_Exec(), HB_ExecFromArray(), HB_FuncPtr(), HB_ObjMsgPtr(), METHOD (Declaration), PROCEDURE |
| Category: | Operators , Indirect execution , Special operators , xHarbour extensions |
| LIB: | xhb.lib |
| DLL: | xhbdll.dll |
// The example shows the difference of indirect execution using a
// code block and a function pointer
PROCEDURE Main
LOCAL pFunc := ( @Test() )
LOCAL bBlock := {|x,y| Test( x, y ) }
? Valtype( bBlock ) // result: B
? Valtype( pFunc ) // result: P
EVal( bBlock, "Hello", "World" )
HB_Exec( pFunc, NIL, "Hello", "World" )
RETURN
PROCEDURE Test( ... )
LOCAL xVal
? PCount()
FOR EACH xVal IN HB_AParams()
?? xVal
NEXT
RETURN
http://www.xHarbour.com