Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Force 4.0 Reference - ptr function pointer declaration http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 ptr                 Function pointer declaration
------------------------------------------------------------------------------
 Syntax
   func|proc [<type>] <funcident> ptr
   [<params>]

 Arguments
   <type> is the return data type of the function.
   <funcident> is the identifier for the function type.
   <params> is an optional parameter list.

 Description
   The ptr keyword declares a function type for use in function
   pointer definitions. A ptr declaration differs from a prototype in that
   the identifier given in the <funcident> argument does not refer to an
   existing function or procedure symbol name. Instead it rather serves
   as a template for determining the generic characteristics of a function
   type, whose instances will be indirectly called in the code via function
   pointer variables.

 Example
   #define EXAMPLE_KEYWORD
   #include example.hdr

   func uint _TEST ptr      // function type declaration
   param const char cText
   
   func uint Test extern    // function declaration
   param const char cText
   
   vardef
      ptr( _TEST ) pFunc := &Test // pointer to function of type _TEST
   enddef
   
   func uint Test static    // function definition
   param const char cText
   // Function that conforms with the _TEST type declaration
   ? cText
   return( len( cText ) )
   endfunc
   
   proc Executor static     // proc receiving function pointer as parameter
   param value ptr( _TEST ) pExec, const char cString
   pExec( cString )         // execute function via its pointer
   endproc
   
   proc Test_ptr
   Test( "Direct call" )    // execute function by direct call
   pFunc( "Indirect call" ) // execute function via its pointer
   Executor( pFunc, "End" ) // pass function pointer to another function
   endproc

   proc main
   Test_ptr()
   endproc

See Also: ptr()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson