02.07.2013 Views

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

HP Fortran Programmer's 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>HP</strong> <strong>Fortran</strong> also allows blank—or unnamed—common to be initialized.<br />

Common block size<br />

<strong>HP</strong> <strong>Fortran</strong> statements<br />

COMMON<br />

The size of a common block is determined by the number and type of the variables it contains.<br />

In the following example, the common block my_block takes 20 bytes of storage: b uses 8 (2<br />

bytes per element) and arr uses 12 (4 bytes per element):<br />

INTEGER(2) b(4)<br />

INTEGER(4) arr(3)<br />

COMMON /cb/b, arr<br />

Data space within the common area for arrays b and arr shown in this example is allocated as<br />

follows:<br />

Table 10-5<br />

Bytes Common block variables<br />

0, 1, 2, 3 b(1), b(2)<br />

4, 5, 6, 7 b(3), b(4)<br />

8, 9, 10, 11 arr(1)<br />

12, 13, 14, 15 arr(2)<br />

16, 17, 18, 19 arr(3)<br />

Allocation common block storage<br />

Common block storage is allocated at link time. It is not local to any one program unit.<br />

Each program unit that uses the common block must include a COMMON statement that<br />

contains the block name, if a name was specified. Variables assigned to the common block by<br />

the program unit need not correspond by name, type, or number of elements with those of any<br />

other program unit. The only consideration is the size of the common blocks referenced by the<br />

different program units. Correspondence between objects in different instances of the same<br />

common block is established by storage association.<br />

Note the following for <strong>HP</strong> <strong>Fortran</strong>: when types with different alignment restrictions are mixed<br />

in a common block, the compiler may insert padding bytes as necessary.<br />

Examples<br />

The following example illustrates how the same common block can be declared in different<br />

program units with different variables but the same size:<br />

Chapter 10 269

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

Saved successfully!

Ooh no, something went wrong!