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 - sizeof() size of variable or type http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 sizeof()            Size of variable or type
------------------------------------------------------------------------------
 Syntax
   sizeof( vartype )

 Arguments
   vartype is any variable, or variable component (array element,
   structure member), or defined data type.

 Description
   The sizeof() operator returns the size of the specified variable or
   data type. The returned value is a numeric constant that represents the
   amount of memory occupied by the operand object in bytes.

   In the current version of Force the size of user-defined structure types
   can not be determined with sizeof() by using their type name. Pass a
   variable of the structure type in question instead.

   When a pointer to a structure is given as the argument for sizeof(),
   the full size of the structure pointed to is returned, not the size
   of the pointer itself (4 bytes for any kind of structure).

 Example
   #define EXAMPLE_OPERATOR
   #include example.hdr

   typedef struct _TEST
      byte        member
      ptr( byte ) pByte
   enddef
   
   dbfdef sDbf
      char( 10 ) cfield
   enddef
   
   indexdef
      char( 10 ) sIdxFld sDbf->cField
   enddef
   
   func uint _FUNC ptr
   
   proc Test_sizeof
   vardef
      int          iVar
      ptr( byte )  pByte
      ptr( _FUNC ) pFunc
      _TEST        sTest
      char         cString
      char( 15 )   cName
      byte         aArr1[ 100 ]
      uint         aArr2[ 100 ]
      byte         aArr3[ 100 ] based cString
   enddef
   
   // data types
   ? sizeof( byte )            // 1
   ? sizeof( int )             // 2
   ? sizeof( uint )            // 2
   ? sizeof( logical )         // 2
   ? sizeof( long )            // 4
   ? sizeof( ulong )           // 4
   ? sizeof( date )            // 4
   ? sizeof( dbl )             // 8
   ? sizeof( char )            // 256
   ? sizeof( ptr )             // 4
   ? sizeof( untyped )         // 4
   ? sizeof( alias )           // 88
   ?
   // variables
   ? sizeof( iVar )            // 2
   ? sizeof( cString )         // 256
   ? sizeof( cName )           // 16
   ? sizeof( pByte )           // 4
   ? sizeof( *pByte )          // 1
   ? sizeof( pFunc )           // 4
   ?
   // whole arrays
   ? sizeof( aArr1 )           // 100
   ? sizeof( aArr2 )           // 200
   ? sizeof( aArr3 )           // 100
   ?
   // array elements
   ? sizeof( aArr3[] )         // 1     (refers to element 0)
   ? sizeof( aArr3[0] )        // 1
   ? sizeof( aArr2[] )         // 2     (refers to element 0)
   ?
   // structures
   ? sizeof( sDbf->cfield )    // 11
   ? sizeof( sIdxFld )         // 11
   ? sizeof( sTest.member )    // 1
   ? sizeof( sTest.pByte )     // 4
   ? sizeof( *sTest.pByte )    // 1
   
   endproc

   proc main
   Test_sizeof()
   endproc

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