### 2.2.5.2 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.

Scalar field references are scalar references because they resolve into single data items having a data type. Aggregate field references are aggregate references because they resolve into references to structured data items: records and nested structure declarations. Aggregate field references are the only references that fall into the aggregate reference category.

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.

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 77 supports no other operations (such as arithmetic or comparison) on aggregate fields.

Compaq Fortran 77 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 77 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 show record and field references. Consider the following structure declarations:

Structure DATE:

    STRUCTURE /DATE/

        INTEGER*1  DAY, MONTH

        INTEGER*2  YEAR

    END 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

- The record NEXT_APP:

      NEXT_APP

- The field APP_TIME(1), an array field of the record NEXT_ APP:

      NEXT_APP.APP_TIME(1)

- The field APP_DATE, a 4-byte array field in the record array APP_LIST(3):

      APP_LIST(3).APP_DATE

Scalar Field References

- The field APP_FLAG, a LOGICAL field of the record NEXT_ APP:

      NEXT_APP.APP_FLAG

- The field HOUR, a LOGICAL*1 subfield of field APP_TIME(1) of record NEXT_APP:

      NEXT_APP.APP_TIME(1).HOUR

- The first character of APP_MEMO(1), a CHARACTER*20 field of the record NEXT_APP:

      NEXT_APP.APP_MEMO(1)(1:1)

- The field MONTH, a LOGICAL*1 subfield of field APP_DATE of record array APP_LIST(1):

      APP_LIST(1).APP_DATE.MONTH

For More Information:

- On specification of fields within structure declarations, see Section 4.17.

- On terminology used to refer to data items, see Section 2.2.6.

- On structure declarations, see Section 4.17.

- On UNION and MAP statements, see Section 4.17.3.

- On the RECORD statement, see Section 4.15.

Previous Page Next Page Table of Contents