Typed Data Declarations
UNIX: The preprocessor recognizes numeric variables declared with the following format:
data_type [*default_type_len]
var_name [*type_len] [(array_spec)]
{, var_name [*type_len] [(array_spec)]
The preprocessor recognizes character variables declared with the following format:
data_type [
*default_type_len[
,]]
var_name [
(array_spec)] [
*type_len]
{, var_name [
(array_spec)] [
*type_len]}
VMS: 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/] }
Windows: 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:
• For information on the allowable
data_types, see
Data Types.
• The default_type_len specifies the size of the declared variable. To specify size for a numeric type variable, use an integer literal of an acceptable length for the particular data type. To specify size for a character type variable, use an integer literal or a parenthesized expression, followed optionally by a comma. The preprocessor does not interpret the length field for variables of type character but merely passes that information to the output file. Note the default type lengths in the following declarations:
C Declares "eage" a 2-byte integer
integer*2 eage
C Declares "stat" a 2-byte integer
logical*2 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 that represents 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 Fortran compilers do not permit the redeclaration of the length of a character variable.
• The variable names must be legal Fortran identifiers.
• The array_spec must conform to Fortran syntax rules. The preprocessor simply notes that the declared variable is an array, but does not parse the array_spec clause.
VMS: 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. Note the following examples of array declarations:
## character*16 enames(100), edepts(15)*10
! Array specification first
## real*4 salestab(5,12), yeartotals*8(12)
! Type length first
• The preprocessor allows you to initialize a variable or array in the declaration statement using the init_clause. The preprocessor accepts, but does not examine, any initial data. The Fortran compiler, however, later detects any errors in the initial data. For example:
## real*8 initcash /512.56/
## character*4 baseyear /'1950'/
## character*4 year /1950/
! 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, use the Fortran
data statement instead.