HP Fortran Programmer's Reference (September 2007)

HP Fortran statements
STRUCTURE (extension)
Chapter 10 473
STRUCTURE /wordmask/
UNION
MAP
INTEGER(KIND=4) :: word
END MAP
MAP
BYTE :: byte0, byte1, byte2, byte3
END MAP
END UNION
END STRUCTURE RECORD /wordmask/ maskrec
If we assign a value to the word field of maskrec, we can then get the individual values of all
four bytes in maskrec by looking at the fields byte0, byte1, byte2, and byte3. To see how the
integer variable word maps onto the byte variables byte0, byte1, byte2, and byte3, use the
following statements:
maskrec.word = 32767
WRITE(*, fmt=100) 'word = ', maskrec.word
WRITE(*, 200) 'byte 0 = ', maskrec.byte0
WRITE(*, 200) 'byte 1 = ', maskrec.byte1
WRITE(*, 200) 'byte 2 = ', maskrec.byte2
WRITE(*, 200) “byte 3 = ', maskrec.byte3
100 FORMAT(A, Z8.8)
200 FORMAT(A, Z2.2)
This code displays the following output:
word = 00007FFF
byte 0 = 00
byte 1 = 00
byte 2 = 7F
byte 3 = FF
Such code, depending as it does on a specific word size, is inherently nonportable.
Related statements
RECORD and TYPE
Related concepts
Derived types are described in “Derived types” on page 123.