Contents - Index


$Common

 

The $COMMON directive provides a means for passing information from the main program to internal functions, procedures, modules, and subprograms.  Use of $COMMON provides an alternative to passing values as arguments. This directive is similar in concept to the COMMON statement in FORTRAN.  It differs in that information flow is one-way.  Variable values can be passed from the main program to the function, procedure or module.  However, if the function, procedure or module changes the value of a variable in COMMON, the change will not be seen in the main program. 

 

The $COMMON statement must directly follow the FUNCTION, PROCEDURE, MODULE, or SUBPROGRAM declaration on a line by itself.  Variables appearing in the $COMMON statement are separated with commas (or semicolons for the EU format), as in the following example.

 

FUNCTION  TESTCOMMON(X)

$COMMON B,C,D {variables B,C, and D are from the main program}

       TESTCOMMON:=X+B+C+D

 END

 B=4;  C=5;  D=6

 G=TESTCOMMON(3)

 

$COMMON should only be used with Functions, Procedures, Modules, and Subprograms appearing in the Equations window.  It should not be used with library functions.  Array Range Notation (e.g., X[1..5] can be used in the $COMMON directive.

 

Note the complex variables can be passed to a Subprogram that is operating in the complex mode with a $Common directive.

 

Directives