FORTRAN 77 Language Reference

PARAMETER

The PARAMETER statement assigns a symbolic name to a constant.

PARAMETER (p=e [, p=e] )

Parameter 

Description 

p

Symbolic name  

e

Constant expression 

An alternate syntax is allowed, if the -xl flag is set: @

PARAMETER p=e [, p=e]

In this alternate form, the type of the constant expression determines the type of the name; no conversion is done.

Description

e can be of any type and the type of symbolic name and the corresponding expression must match.

A symbolic name can be used to represent the real part, imaginary part, or both parts of a complex constant.

A constant expression is made up of explicit constants and parameters and the FORTRAN operators. See "Constant Expressions" for more information.

No structured records or record fields are allowed in a constant expression.

Exponentiation to a floating-point power is not allowed, and a warning is issued.

If the type of the data expression does not match the type of the symbolic name, then the type of the name must be specified by a type statement or IMPLICIT statement prior to its first appearance in a PARAMETER statement, otherwise conversion will be performed.

If a CHARACTER statement explicitly specifies the length for a symbolic name, then the constant in the PARAMETER statement can be no longer than that length. Longer constants are truncated, and a warning is issued. The CHARACTER statement must appear before the PARAMETER statement.

If a CHARACTER statement uses *(*) to specify the length for a symbolic name, then the data in the PARAMETER statement are used to determine the length of the symbolic constant. The CHARACTER statement must appear before the PARAMETER statement.

Any symbolic name of a constant that appears in an expression e must have been defined previously in the same or a different PARAMETER statement in the same program unit.

Restrictions

A symbolic constant must not be defined more than once in a program unit.

If a symbolic name appears in a PARAMETER statement, then it cannot represent anything else in that program unit.

A symbolic name cannot be used in a constant format specification, but it can be used in a variable format specification.

If you pass a parameter as an argument, and the subprogram tries to change it, you may get a runtime error.

Examples

Example 1: Some real, character, and logical parameters:


       CHARACTER HEADING*10 
       LOGICAL T 
       PARAMETER (EPSILON=1.0E-6, PI=3.141593, 
&                 HEADING=' IO Error #', 
&                 T=.TRUE.) 
       ... 

Example 2: Let the compiler count the characters:


       CHARACTER HEADING*(*) 
       PARAMETER (HEADING='I/O Error Number') 
       ... 

Example 3: The alternate syntax, if the -xl compilation flag is specified:


       PARAMETER FLAG1 = .TRUE. 

The above statement is treated as:


       LOGICAL FLAG1 
       PARAMETER (FLAG1 = .TRUE.)

An ambiguous statement that could be interpreted as either a PARAMETER statement or an assignment statement is always taken to be the former, as long as either the -xl or -xld option is specified.

Example: An ambiguous statement:


       PARAMETER S = .TRUE.

With -xl, the above statement is a PARAMETER statement about the variable S.


       PARAMETER S = .TRUE. 

It is not an assignment statement about the variable PARAMETERS.


       PARAMETERS = .TRUE.