next up previous contents index
Next: SAVE Statements and Common Up: Using Common Blocks Previous: Data Types

Storage Units

The length of each common block is measured in storage units, as described in section 5.1. In summary, integer, real, and logical items occupy one numeric storage unit each; complex and double precision items occupy two each. To maximise portability, character storage units are considered incommensurate with numerical storage units. For this reason character and non-character items cannot be mixed in the same common block.

In practice this often means that two common blocks are needed to hold a particular data structure: one for the character items and one for all the others. If, in the first example, it had been necessary for the plotting package to store a plot title this would have to appear in a separate common block such as:

 
       COMMON /PLOTC/ TITLE 
       CHARACTER TITLE*40 
       SAVE /PLOTC/

It is good practice to use related names for the blocks to indicate that the character and non-character items are used in conjunction.

The length of a named common block must be the same in each program unit in which it appears. Obviously the easiest way to ensure this is to make the common block contents identical in each program unit. Note, however, that there is no requirement for data types to match, or for them to be listed in any particular order, provided the items are not used for information transfer, and provided the total length of the block is the same in each case. Thus these common blocks are both 2000 numerical storage units in length:

 
       COMMON /SAME/ G(1000) 
       DOUBLE PRECISION G 

       COMMON /SAME/ A, B, C, R(1997) 
       REAL A, R 
       LOGICAL B 
       INTEGER C

Items in a common block are stored in consecutive memory locations. Unfortunately there a few computer systems which require double precision and complex items to be stored in even-numbered storage locations: these may find it hard to cope with blocks which contain a mixture of data types. Machines with this defect can nearly always be placated by arranging for all double precision and complex items to come at the beginning of each block.


next up previous contents index
Next: SAVE Statements and Common Up: Using Common Blocks Previous: Data Types

Mario Storti
Wed Nov 4 19:32:56 ART 1998