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 - & address operator (unary) http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 &                   Address operator (unary)
------------------------------------------------------------------------------
 Syntax
   &xObject

 Arguments
   xObject is a symbol (variable or function) or a literal string.

 Description
   The & operator returns the address of a memory object. The numeric
   returned by the & operator is a 32-bit wide ulong value that specifies
   (points to) the location in memory where the passed object resides. This
   value can then be assigned to a pointer variable, for indirectly
   referencing the respective object.

   The & operator performs equivalently to the addr() function, but its use
   is preferred in terms of efficiency.

 Example
   #define EXAMPLE_OPERATOR
   #include example.hdr

   proc TESTFUNC ptr
   param value ptr( char( 10 ) ) pChg
   
   proc Indirect static
   param value ptr( char( 10 ) ) pChg
   *pChg := "there" // change the string pointed to by the paramater
   endproc
   
   proc Test_944
   vardef
      char( 10 )        cString
      ptr( char( 10 ) ) pChar
      ptr( TESTFUNC )   pFunc
      ptr( byte )       pByte
   enddef
   cString := "hello"               // initialize string
   ? cString                        // display original value
   pChar := &cString                // assign pointer to string
   pFunc := &Indirect               // assign function pointer
   pFunc( pChar )                   // indirect call
   ? cString                        // print changed string
   pByte := pChar + 3               // point to fourth byte of string
   *pByte := 0                      // terminate string
   ? cString                        // print truncated string
   endproc

   proc main
   Test_944()
   endproc

See Also: * addr() ptr()

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