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 - based union data storage modifier http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 based               Union data storage modifier
------------------------------------------------------------------------------
 Syntax
   vardef
      <datatype> <var> based <basevar>
   enddef

 Arguments
   <datatype> is the data type of the variable being declared.

   <var> is the symbol name of the variable being declared.

   <basevar> is the symbol name of the variable with which the
   variable being declared shares memory location.

 Description
   The based keyword is used to establish data aggregations.
   It allows multiple data objects to share the same storage space,
   similarly to unions in the C language. The data objects superimposed
   on each other can have different data types. Changes to any of the
   members of the aggregate result in altering all other variables
   in the shared memory area.

   Based variables inherit their scope from their base variable. This
   means a based variable declared in a public vardef block becomes static
   if based on a static variable.

   Based variables provide a convenient way of looking at the same data from
   different points of view, like accessing the characters of a string
   variable as individual bytes. In this case a byte array is based on a
   char variable.

 Example
   #define EXAMPLE_KEYWORD
   #include example.hdr

   // This example employs a byte array based on a char variable for
   // examining individual bytes of the string. Use of the ptr( byte )
   // data type is preferred, however.
   
   proc Test_based
   vardef
      char( 25 ) cSourcePath
      byte       aBytes[25] based cSourcePath
   enddef
   cSourcePath := "C:\APPLICATION"
   if aBytes[ 0 ] == 'A'
      ? "Reading from A: drive."
   else
      if aBytes[0] = 'B'
         ? "Reading from B: drive."
      else
         ? "Reading from a hard drive."
      endif
   endif
   endproc

   proc main
   Test_based()
   endproc

See Also: typedef struct

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