15.1.5 DEFINE and UNDEFINE Directives

The DEFINE directive creates a symbolic variable whose existence or value can be tested during conditional compilation. The UNDEFINE directive removes a defined symbol.

The DEFINE and UNDEFINE directives take the following forms: [See Note]

cDEC$ DEFINE name [=val]

Is one of the following: C (or c), !, or * (see Section 15.1.1).

Is the name of the variable.

Is an INTEGER(4) value assigned to name.

Rules and Behavior

DEFINE and UNDEFINE create and remove variables for use with the IF (or IF DEFINED) directive. Symbols defined with the DEFINE directive are local to the directive. They cannot be declared in the Fortran program.

Because Fortran programs cannot access the named variables, the names can duplicate Fortran keywords, intrinsic functions, or user-defined names without conflict.

To test whether a symbol has been defined, use the IF DEFINED (name) directive You can assign an integer value to a defined symbol. To test the assigned value of name, use the IF directive. IF test expressions can contain most logical and arithmetic operators.

Attempting to undefine a symbol which has not been defined produces a compiler warning.

The DEFINE and UNDEFINE directives can appear anywhere in a program, enabling and disabling symbol definitions.


Consider the following:

 !DEC$ DEFINE testflag
 !DEC$ IF DEFINED (testflag)
    WRITE (*,*) 'Compiling first line'
    WRITE (*,*) 'Compiling second line'
 !DEC$ UNDEFINE testflag

Note: The following forms are also allowed: !MS$DEFINE name[=val] and !MS$UNDEFINE name

For More Information:

Previous Page Next Page Table of Contents