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 - static static data storage class http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 static              Static data storage class
------------------------------------------------------------------------------
 Syntax
   vardef static
      <declarations>
   enddef

 Arguments
   <declarations> is a list of variable declarations.

 Description
   The static keyword modifies the storage class of all data objects
   declared in the respective declaration block to become static.
   Static vardef blocks are placed outside of code blocks.

   Static objects exist for the life of the program. A static variable
   retains its value across function calls, unlike a local variable
   which is reinitialized each time its parent function is called. A
   static variable has permanent life, and its scope is limited to the
   source module in which it is declared. The scope of statics is from
   the point of declaration through the end of the source code file.

   When used with a function definition, the static class restricts the
   function's visibility such that the function can only be called
   by name from functions defined in the same source code file. Static
   functions can be executed from other modules indirectly, via their
   pointers passed to external functions as parameters.

 Example
   #define EXAMPLE_KEYWORD
   #include example.hdr

   // Static variables and functions are only accessible within the
   // source module within which their definition occurs.
   
   vardef static              // various static data objects
      char    cString
      uint    aNums[ 30000 ]  // a 60 Kbytes array
      uint    nNum
      logical lLog
      dbl     eBig
   enddef
   
   proc Test static           // static function
   cString    := "hello"      // initialize data
   nNum       := 102
   aNums[ 1 ] := 101
   lLog       := .t.
   eBig       := -565.98
   
   ? cString                  // print values
   ? nNum
   ? aNums[ 1 ]
   ? lLog
   ? eBig
   endproc
   
   proc Test_static
   Test()
   endproc

   proc main
   Test_static()
   endproc

See Also: public sfar

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