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 - param parameter indicator http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 param               Parameter indicator
------------------------------------------------------------------------------
 Syntax
   <func>
   param [<modifier>] <datatype> <symbol> [,...]
   <code>
   endfunc|endproc

 Arguments
   <func> is a function or procedure declaration.

   <modifier> determines the passing method for the parameter.

   <datatype> is the data type of the parameter.

   <symbol> is the symbol name of the parameter.

   <code> is the body of code for the function.

 Description
   The param keyword initiates the declaration of one or more
   function parameters. The parameter declaration must immediately
   follow the function declaration. The param keyword is followed
   by a list of <modifier> <datatype> <symbol> sequences, each separated
   by a comma.

   The characteristics of various parameter passing methods are listed in
   the table below.

   ------------------------------------------------------------------------
   Keyword  Passing       Object      Parameter contents       Modifiable
            method        on stack  -----------------------  --------------
                                    Var. Field Expr. Const.  Original  Copy
   ------------------------------------------------------------------------

   <none>   by reference  address   yes  no    no    no      yes       no
   const    by reference  address   yes  yes   yes   yes     no        no
   field    by reference  address   no   yes   no    no      no        no
   value    by value      value     yes  yes   yes   yes     no        yes
   ------------------------------------------------------------------------

   The default parameter passing method is by reference, that is the
   4-byte address of the parameter object is placed on the stack at
   function call time, provided the optional <modifier> statement is not
   specified in the parameter declaration. In this case the function that
   receives the parameter can directly modify the contents of the respective
   memory area, and the change will be reflected in the parameter variable's
   value after the function returned to its caller. The mechanism provides
   a way of "returning" several values from a function, by altering several
   parameters passed by reference. Only named variables can be applied this
   way, while expressions and constant values can not (as they do not have
   an assigned memory area).

   If any of the possible <modifier> keywords is used in the declaration of
   a certain parameter, then the called function has no access to the
   contents of the original variable, thus can not modify it.

   In the case of the const and field modifiers the parameters are
   passed by reference (address) as well, however the compiler does not
   allow assignments to them. This mechanism provides a protection to
   parameters that are long enough to be passed by reference (typically
   chars), but they should be read only in the called function.

   In contrast to the above three by-reference parameter passing methods, the
   value modifier causes the literal value of the argument to be
   copied on the stack. Variables, expressions and constants can equally
   participate in this sort of parameter passing. The called function is
   free to modify the values received on the stack, however such
   alterations have no effect from the point of view of the caller
   function.

 Example
   #define EXAMPLE_KEYWORD
   #include example.hdr

   proc Test static
   param char cMsg, value uint uLenMax, value logical lVerbose, ;
      const char cText
   if len( cMsg ) < uLenMax
      cMsg += " world"
      if lVerbose
         ? cText
      endif
   endif
   endproc
   
   proc Test_param
   vardef
      char cMessage
   enddef
   cMessage := "Hello"
   Test( cMessage, ( sizeof( char ) - 1 ) - len( cMessage ), .t., ;
      "String appended" )
   ? cMessage
   endproc

   proc main
   Test_param()
   endproc

See Also: func proc

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