next up previous contents index
Next: Guidelines Up: Named Constants Previous: Named Constants

PARAMETER Statement

  The general form of the PARAMETER statement is:
PARAMETER ( cname = cexp, cname = cexp, ... )
where each cname is a symbolic name which becomes the name of a constant, and each cexp is a constant expression of a suitable data type.

The terms in a constant expression can only be literal constants or named constants defined earlier in the same program unit. Variables, array elements, and function references are not permitted at all. Otherwise the usual rules for expressions apply: parentheses can be used around sub-expressions, and the arithmetic types can be intermixed. There is one restriction on exponentiation: it can only be used to raise a number to an integer power. The normal rules for assignment statements apply: for arithmetic types suitable conversions will be applied if necessary; character strings will be truncated or padded to the required length. Note that substring references are not permitted in character constant expressions.

PARAMETER statements are specification statements and may precede or follow type statements. But any type (or IMPLICIT) statement which affects the data type or length of a named constant must precede it. Subject to these rules, PARAMETER statements are permitted to precede IMPLICIT statements. This makes it possible for a named constant to set the default length for the character type for certain ranges of initial letters. For example:

 
      PROGRAM CLEVER 
      PARAMETER (LENCD = 40, LENE = 2 * LENCD) 
      IMPLICIT CHARACTER*(LENCD)(C-D), CHARACTER*(LENE)(E) 
      PARAMETER (DEMO = 'This is exactly 40 chars long')
Once defined, a named constant can be used in any expression, including a dimension-bound expression, or in a DATA statement. A named constant cannot be used just as part of another constant (for example one component of a complex constant) and named constants are not permitted at all within format specifications.


next up previous contents index
Next: Guidelines Up: Named Constants Previous: Named Constants
Helen Rowlands
8/27/1998