STRUCTURE Statement (Nonexecutable) [ HP FORTRAN 77/iX Reference ] MPE/iX 5.0 Documentation
HP FORTRAN 77/iX Reference
STRUCTURE Statement (Nonexecutable)
The STRUCTURE statement names and begins the declaration of a structure
in a structure block. A structure is the "data type" of a record
variable. It must be declared before a RECORD statement can refer to it.
The END STRUCTURE statement terminates a structure block.
A structure block has the following elements:
STRUCTURE statement Begins the structure declaration.
Declaration body Declares the fields of the structure,
including their names, data types,
order, and alignment. Fields are in
the order of their declaration in the
structure.
END STRUCTURE statement Ends the structure declaration.
STRUCTURE Statement
END STRUCTURE Statement
-----------------------------------------------------------------------------------------------
| | | |
| Item | Description/Default | Restrictions |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| struc_name | Name of the structure. Used in | Required at the outermost level of |
| | the RECORD statement to define the | the structure. Can also be used |
| | form of a record variable. | to name a substructure. |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| field_name | Field name for a substructure. | Required for a substructure. Not |
| | | permitted at the outermost level |
| | | of the structure. |
| | | |
-----------------------------------------------------------------------------------------------
Semantics
The declaration body consists of declaration statements that define
symbolic names. The symbolic names are the field names of the structure.
These field declarations can be any combination of the following:
Type specification Any type specification statement
statement defining variables or array declarators.
Substructure declaration A substructure can be declared in two
ways:
1. With a RECORD statement using a
previously defined structure.
2. As a structure declaration block
having a field_name.
If a struc_name is also
specified, the substructure can
be referenced as a structure
declaration by a subsequent
RECORD statement.
Recursive structure declarations
are not permitted. A structure
which is currently being defined
can not refer to itself.
Union declaration A union declaration block, described
below, specifies two or more fields that
share a common location within the
structure.
Unnamed field The special symbolic name, %FILL, can be
used in a structure as the "name" of an
empty field. %FILL is described below.
Structure names must be unique between structures. However, structure
fields, variables, and common blocks can have the same name as a
structure.
Field names must be unique at the same structure level. However, for
example, a structure can contain a field named field1 and a substructure
of that structure can also contain a field named field1.
For convenience in declaring constants, PARAMETER statements may be
placed between the statements in a structure block. However, it is
important to note that a PARAMETER statement within a structure block has
the same effect as if it were outside the block.
NOTE A structure declaration does not allocate storage. Structure
declarations only specify the form for a record.
Field Declarations
All fields declared within a structure must be explicitly typed. The
IMPLICIT statement has no effect on field names within a structure
declaration block.
A field that is an array must be specified as an array name with
dimension declarator within the explicit type specification statement.
The DIMENSION statement is not permitted within a structure. For
example:
REAL*4 field2(10)
declares field2 to be an array of 10 4-byte real values.
Dynamic, assumed size, or adjustable arrays can not be declared within a
structure declaration. Also, character items with passed length or
variable length can not be declared within a structure.
Unnamed Fields
Unnamed fields, substructures, and records can be declared in a structure
by using the special name %FILL as a dummy field name. These unnamed
fields can be used for alignment. They cannot be referenced or
initialized. For example:
STRUCTURE /align/
CHARACTER*3 shortname
BYTE %FILL
REAL*4 vector(10)
END STRUCTURE
Data Initialization
Fields within a structure can be given initial values, using
the initialization rules for the type specification statements.
Uninitialized fields are undefined until they are assigned values.
Unnamed fields cannot be initialized.
When a record is declared, its fields are initialized to the values
specified in the structure declaration.
If more than one map block initializes the same area in a union block,
the last initialization takes precedence.
UNION Statement (Nonexecutable)
The UNION statement begins the declaration of a union block in a
structure block. A union block defines a shared data section of a
structure. The END UNION statement terminates a union block.
A union block has the following elements:
UNION statement Begins the union declaration.
Declaration body Two or more map declaration blocks.
END UNION statement Ends the union declaration.
UNION Statement
END UNION Statement
A union declaration defines the form of a data location within a
structure that is shared by different groups of data items during program
execution. The data groups are defined with map declaration blocks in
the union declaration. The map blocks share the same physical storage
space. When one field of a map block is accessed then all the fields in
that map are defined and the fields of the other maps in that union are
undefined.
The overall size of a union declaration is the size of the largest map
block within the union.
MAP Statement (Nonexecutable)
The MAP statement begins the declaration of a map block in a union
declaration block. The END MAP statement terminates a map block.
A MAP block has the following elements:
MAP statement Begins the MAP declaration.
Declaration body Declares the fields of the map block,
including their names, data types,
order, and alignment. Fields are in
the order of their declaration.
END MAP statement Ends the MAP declaration.
MAP Statement
END MAP Statement
A map declaration block specifies the form of the fields within a union
declaration block. The rules for a map declaration body are the same as
the rules for a structure declaration body.
Each map block within a union begins at the same data location in memory.
Consequently, the initialization of fields within one map may affect and
be affected by initializations within another map. The same data area
may be initialized more than once. Only the last initialization of that
area is valid. For example, in the following union block:
UNION
MAP
CHARACTER*8 a /"01234567"/
END MAP
MAP
CHARACTER*4 b
CHARACTER*4 c /"ABCD"/
END MAP
END UNION
field b is initialized to "0123", c to"ABCD", and a to "0123ABCD".
Examples Notes
--------------------------------------------------------------------------------------
STRUCTURE /num1/ The structure num1 defines two 4-byte integer
INTEGER*4 i, j fields, i and j, which occupy consecutive words in
END STRUCTURE memory.
STRUCTURE /num2/ The structure num2 defines a union that contains
UNION two map blocks. The first map consists of a 4-byte
MAP integer, i, followed by a 4-byte real, a. The
INTEGER*4 i second map consists of a 4-byte integer, j,
REAL*4 a followed by an array, x, of 10 1-byte logical
END MAP elements. Integers i and j occupy the same storage
MAP location. Real a occupies the same storage as the
INTEGER*4 j first four elements of array x. The entire union
LOGICAL*1 x(10) is 14 bytes long.
END MAP
END UNION The record overlay has the structure of num2. It
END STRUCTURE has the following fully qualified variable names:
RECORD /num2/ overlay
overlay - a record or aggregate
overlay.i - a 4-byte integer
overlay.a - a 4-byte real
overlay.j - a 4-byte integer
overlay.x - an array of 10 1-byte logicals
STRUCTURE /outer/ The structure outer contains a substructure
STRUCTURE /inner/ self declaration having both a struc_name, inner, and a
INTEGER*4 ssn field_name, self. The struc_name allows the
INTEGER*2 age substructure to be used as a structure form in the
CHARACTER*18 name RECORD statement that defines the field spouse and
END STRUCTURE in the separate RECORD statement that defines
RECORD /inner/ spouse someone. The second RECORD statement in the
RECORD /num1/ data structure refers to the structure num1 defined
END STRUCTURE above.
RECORD /outer/ personal
RECORD /inner/ someone The record personal has the following fully
qualified variable names:
personal - a record or aggregate
personal.self - a record or aggregate
personal.self.ssn - a 4-byte integer
personal.self.age - a 2-byte integer
personal.self.name - an 18-byte character
personal.spouse - a record or aggregate
personal.spouse.ssn - a 4-byte integer
personal.spouse.age - a 2-byte integer
personal.spouse.name - an 18-byte character
personal.data - a record or aggregate
personal.data.i - a 4-byte integer
personal.data.j - a 4-byte integer
The record someone has the following fully
qualified variable names:
someone - a record or aggregate
someone.ssn - a 4-byte integer
someone.age - a 2-byte integer
someone.name - an 18-byte character
MPE/iX 5.0 Documentation