Variable and Type Declarations
The preprocessor recognizes numeric variables declared with the following format:
data_type [*default_type_len]
var_name [*type_len] [(array_spec)] [/init_clause/]
{, var_name [*type_len] [(array_spec)] [/init_clause/]}
The preprocessor recognizes character variables declared with the following format:
data_type [*default_type_len[,]]
var_name [(array_spec)] [*type_len] [/init_clause/]
{, var_name [(array_spec)] [*type_len] [/init_clause/]}
Syntax Notes:
• A variable or type name must begin with an alphabetic character, which can be followed by alphanumeric characters. In VMS and Windows, it can also be followed by underscores.
• For information on the allowable
data_types, see
Data Types (see page
Data Types) in this chapter.
• The default_type_len specifies the size of the variable being declared. For variables of numeric type, it must be represented by an integer literal of an acceptable length for the particular data type. For variables of character type, it can be represented by an integer literal or a parenthesized expression followed optionally by a comma. The preprocessor does not parse the length field for variables of type character. Note the default type lengths in the declarations shown below:
C Declares "eage" a 2-byte integer
integer*2 eage
C Declares "stat" a 4-byte integer
integer*4 stat
C Declares "ename" a character string
character*(4+len) ename
• The type_len allows you to declare a variable with a length different from default_type_len. Again, you can use a parenthesized expression only to declare the length of character variable declarations. The type length for a numeric variable must be an integer literal representing an acceptable numeric size. For example:
C Default-sized integer and 2-byte integer
integer length
integer*2 height
character*15 name, socsec*(numlen)
Some UNIX Fortran compilers do not permit the length of a character variable to be redeclared.
• The data type and variable names must be legal Fortran identifiers beginning with an alphabetic character. In VMS, it can also begin with an underscore.
• The array_spec should conform to Fortran syntax rules. The preprocessor simply notes that the declared variable is an array but does not parse the array_spec clause. Note that if you specify both an array and a type length, the order of those two clauses differs depending on whether the variable being declared is of character or numeric type. The following are examples of array declarations:
C Array specification first
character*16 enames(100), edepts(15)*10
C Type length first
real*4 saltab(5,12), real*8 yrtots(12)
• The preprocessor allows you to initialize a variable or array in the declaration statement by means of the init_clause. The preprocessor accepts, but does not examine, any initial data. The Fortran compiler, however, will later detect any errors in the initial data. For example:
real*8 initcash /512.56/
character*4 baseyear /'1950'/
character*4 year /1950/
C Acceptable to preprocessor but not to compiler
Do not continue initial data over multiple lines. If an initialization value is too long for the line, as could be the case with a string constant, instead use the Fortran DATA statement. For UNIX, init_clause is an extension to the F77 standard.