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 - vardef variable declaration block http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 vardef              Variable declaration block
------------------------------------------------------------------------------
 Syntax
   vardef [<scope>]
      <type> <varlist>
   enddef

 Arguments
   <scope> is the range of visibility for data objects in the declaration
   block (public, static, far, sfar, extern).

   <type> is a primitive or derived data type.

   <variable> is the symbol name for a variable. More than one variable
   of the same type can be declared in a comma-separated list, except for
   structures.

 Description
   The vardef keyword initiates a variable declaration block.
   Vardef blocks are used to declare variables for all data types except
   for composite ones like database aliases and indexes.

   When a vardef block is placed outside of a code block, the variables
   declared in it are allocated in a (far) data segment, and have public
   (global) or static scope. In contrast, the variables declared in a vardef
   block which is placed in a code block are allocated in the stack segment,
   and their scope is local to the code block in which their declaration
   occurred.

   Static and public variables can be initialized at the time of declaration,
   but local variables can not. For non-local variables the initialization
   can be multiple, that is several variables can be initialized on the
   same source line.

 Example
   #define EXAMPLE_KEYWORD
   #include example.hdr

   // multiple variable initializations
   vardef
      uint    nVar6, nVar7, nVar8 := 2            // only nVar8 gets a value
      uint    aArr1[2], aArr2[2] := 4, 6          // only aArr2[] gets a value
      uint    nVar9 := nVar10 := nVar11 := 3      // all gets the same value
      uint    nVar12, nVar13 := nVar14 := 4, nVar15 := 5   // mixed
      logical lLog1 := lLog2 := .t., lLog3 := lLog4 := .f. // multiple
   enddef
   
   vardef                     // public declaration block
      dbl     eBig
   enddef
   
   vardef public              // public declaration block
      char    cString
   enddef
   
   vardef static              // static declaration block
      uint    aNums[ 30 ]
   enddef
   
   vardef far                 // far declaration block
      uint    nNum
   enddef
   
   vardef sfar                // static far declaration block
      logical lLog
   enddef
   
   vardef extern              // external declaration block
      byte    __syscolor[ 32 ]
   enddef
   
   proc Test_vardef
   cString    := "hello"      // initialize data
   nNum       := 102
   aNums[ 1 ] := 101
   lLog       := .t.
   eBig       := -565.98
   
   ? cString                  // print values
   ? nNum
   ? aNums[ 1 ]
   ? lLog
   ? eBig
   endproc

   proc main
   Test_vardef()
   endproc

See Also: extern far public sfar static

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