FORTRAN 77 Language Reference

Fields in a Map

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

A map declaration 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. The amount of memory used by a union is that of its biggest map.

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

If you define the variable PERSON to have the structure /STUDENT/ from the above example, then PERSON.MAJOR references a field from the first map, and PERSON.CREDITS references a field from the second map. If the variables of the second map field are initialized, and then the program references the variable PERSON.MAJOR, the first map becomes active, and the variables of the second map become undefined.