FORTRAN 77 Language Reference

UNION and MAP

The UNION @ statement defines groups of fields that share memory at runtime.

The syntax of a UNION declaration is as follows:


UNION
       MAP
              field-declaration
              field-declaration
              ...
       MAP
              field-declaration
              field-declaration
              ...
       END 
MAP
END UNION

Description

A MAP statement defines alternate groups of fields in a union. During execution, one map at a time is associated with a shared storage location. When you reference a field in a map, the fields in any previous map become undefined, and are succeeded by the fields in the map of the newly referenced field. Also:

The UNION line is part of an inherently multiline group of statements, and neither the UNION line nor the END UNION line has any special indication of continuation. You do not put a nonblank in column six, nor an & in column one.

Each field-declaration in a map declaration can be one of the following:

Example

Declare the structure /STUDENT/ to contain either NAME, CLASS, and MAJOR, or NAME, CLASS, CREDITS, and GRAD_DATE:


       STRUCTURE /STUDENT/ 
       CHARACTER*32  NAME 
       INTEGER*2  CLASS 
       UNION 
              MAP 
                     CHARACTER*16 MAJOR 
              END MAP 
              MAP 
                     INTEGER*2  CREDITS 
                     CHARACTER*8  GRAD_DATE 
              END MAP 
       END UNION 
       END STRUCTURE 
       RECORD /STUDENT/ PERSON 

In the above example, the variable PERSON has the structure /STUDENT/, so: