xHarbour Reference Documentation > Operator Reference xHarbour Developers Network  

@()

Function-reference operator (unary): obtains a function pointer.

Syntax

( @<funcName>() )  -->  pFuncPointer

Arguments

<funcName>
<funcName> is the symbolic name of a function or procedure to obtain the function pointer from. Note that the function-reference operator can only be used within parentheses. If this syntactical rule is not complied with, a syntax error is reported by the compiler.

Description

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().

Info

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

Example

// 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

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe