B.12.3 References to Record Fields

References to record fields must correspond to the kind of field being referenced. Aggregate field references refer to composite structures (and substructures). Scalar field references refer to singular data items, such as variables.

An operation on a record can involve one or more fields.

Record field references take one of the following forms:

Aggregate Field Reference:

record-name [.aggregate-field-name] . . .

Scalar Field Reference:

record-name [.aggregate-field-name] . . .   .scalar-field-name

record-name
Is the name used in a RECORD statement to identify a record.


aggregate-field-name
Is the name of a field that is a substructure (a record or a nested structure declaration) within the record structure identified by the record name.


scalar-field-name
Is the name of a data item (having a data type) defined within a structure declaration.

Rules and Behavior

Records and record fields cannot be used in EQUIVALENCE statements. However, you can make fields of record structures equivalent to themselves by using the UNION and MAP statements in a structure declaration.

Records and record fields cannot be used in DATA statements, but individual fields can be initialized in the STRUCTURE definition.

An automatic array cannot be a record field.

A scalar field reference consists of the name of a record (as specified in a RECORD statement) and zero or more levels of aggregate field names followed by the name of a scalar field. A scalar field reference refers to a single data item (having a data type) and can be treated like a normal reference to a Fortran variable or array element.

You can use scalar field references in statement functions and in executable statements. However, they cannot be used in COMMON, SAVE, NAMELIST, or EQUIVALENCE statements, or as the control variable in an indexed DO-loop.

Type conversion rules for scalar field references are the same as those for variables and array elements.

An aggregate field reference consists of the name of a record (as specified in a RECORD statement) and zero or more levels of aggregate field names.

You can only assign an aggregate field to another aggregate field (record = record) if the records have the same structure. Compaq Fortran supports no other operations (such as arithmetic or comparison) on aggregate fields.

Compaq Fortran requires qualification on all levels. While some languages allow omission of aggregate field names when there is no ambiguity as to which field is intended, Compaq Fortran requires all aggregate field names to be included in references.

You can use aggregate field references in unformatted I/O statements; one I/O record is written no matter how many aggregate and array name references appear in the I/O list. You cannot use aggregate field references in formatted, namelist, and list-directed I/O statements.

You can use aggregate field references as actual arguments and record dummy arguments. The declaration of the dummy record in the subprogram must match the form of the aggregate field reference passed by the calling program unit; each structure must have the same number and types of fields in the same order. The order of map fields within a union declaration is irrelevant.

Records are passed by reference. Aggregate field references are treated like normal variables. You can use adjustable arrays in RECORD statements that are used as dummy arguments.


Note: Because periods are used in record references to separate fields, you should not use relational operators (.EQ., .XOR.), logical constants (.TRUE., .FALSE.), and logical expressions (.AND., .NOT., .OR.) as field names in structure declarations.

Examples

The following examples demonstrate record and field references. Consider the following structure declarations:

Structure DATE:

 STRUCTURE /DATE/
   INTEGER*1 DAY, MONTH
   INTEGER*2 YEAR
 STRUCTURE

Structure APPOINTMENT:

 STRUCTURE /APPOINTMENT/
   RECORD /DATE/      APP_DATE
   STRUCTURE /TIME/   APP_TIME(2)
     INTEGER*1        HOUR, MINUTE
   END STRUCTURE
   CHARACTER*20       APP_MEMO(4)
   LOGICAL*1          APP_FLAG
 END STRUCTURE

The following RECORD statement creates a variable named NEXT_APP and a 10-element array named APP_LIST. Both the variable and each element of the array take the form of the structure APPOINTMENT.

 RECORD /APPOINTMENT/    NEXT_APP,APP_LIST(10)

Each of the following examples of record and field references are derived from the previous structure declarations and RECORD statement:

Aggregate Field References

Scalar Field References

For More Information:


Previous Page Next Page Table of Contents