24.11.2014 Views

Open Watcom FORTRAN 77 Language Reference

Open Watcom FORTRAN 77 Language Reference

Open Watcom FORTRAN 77 Language Reference

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Language</strong> <strong>Reference</strong><br />

SUBROUTINE PRINT_ITEM( ITEM )<br />

STRUCTURE /DATA_MAP/<br />

INTEGER TYPE<br />

UNION<br />

MAP<br />

LOGICAL<br />

END MAP<br />

MAP<br />

INTEGER<br />

LGL<br />

INT<br />

END MAP<br />

MAP<br />

REAL<br />

FLT<br />

END MAP<br />

MAP<br />

DOUBLE PRECISION DBL<br />

END MAP<br />

END UNION<br />

END STRUCTURE<br />

RECORD /DATA_MAP/ ITEM<br />

END<br />

IF( ITEM%TYPE .EQ. 1 ) THEN<br />

PRINT ’(L2)’, ITEM%LGL<br />

ELSEIF( ITEM%TYPE .EQ. 2 ) THEN<br />

PRINT ’(I8)’, ITEM%INT<br />

ELSEIF( ITEM%TYPE .EQ. 3 ) THEN<br />

PRINT ’(E12.5)’, ITEM%FLT<br />

ELSEIF( ITEM%TYPE .EQ. 4 ) THEN<br />

PRINT ’(D12.5)’, ITEM%DBL<br />

ENDIF<br />

The organization of the record in memory is as follows:<br />

offset +0 +4 +8<br />

integer logical (slack)<br />

integer<br />

real<br />

(slack)<br />

(slack)<br />

double precision<br />

The first 4 bytes of storage are occupied by TYPE. The next 4 to 8 bytes of storage are occupied by either<br />

LGL, INT, FLT, or DBL depending on the interpretation of the contents of the variable TYPE. The size<br />

of the record ITEM is a total of 12 bytes. Based on the conventions of the above program example, only 8<br />

bytes of the record ITEM are used when TYPE is 1, 2, or 3. When TYPE is 4 then 12 bytes of the record<br />

are used.<br />

The following example maps out a 4-byte integer on an Intel 80x86-based processor.<br />

170 Unions

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!