FORTRAN 77 Language Reference

Size and Alignment of Data Types

Storage and alignment are always given in bytes. Values that can fit into a single byte are byte-aligned.

The size and alignment of types depends on various compiler options and platforms, and how variables are declared. The maximum alignment in COMMON blocks is to 4-byte boundaries.

Default data alignment and storage allocation can be changed by compiling with special options, such as -f, -dalign, -dbl_align_all, -dbl, -r8, -i2, and -xtypemap. The default descriptions in this manual assume that these options are not in force.

Refer to the Fortran User's Guide for details of specific compiler options.

The following table summarizes the default size and alignment, ignoring other aspects of types and options.

Table 2-1 Default Data Sizes and Alignments (in Bytes)

Fortran 77 Data Type 

Size  

  Default Alignment  

SPARC x86 

  Alignment in COMMON  

SPARC  x86 

BYTE X

CHARACTER X

CHARACTER*n X

COMPLEX X

COMPLEX*8 X

DOUBLE COMPLEX X

COMPLEX*16 X

COMPLEX*32 X

16 

16 

32 

8/16 

-- 

-- 

DOUBLE PRECISION X

REAL X

REAL*4 X

REAL*8 X

REAL*16 X

16 

8/16 

-- 

-- 

INTEGER X

INTEGER*2 X

INTEGER*4 X

INTEGER*8 X

LOGICAL X

LOGICAL*1 X

LOGICAL*2 X

LOGICAL*4 X

LOGICAL*8 X

Note the following:

Compiling with options -i2,-r8, or -dbl changes the defaults for certain data declarations that appear without an explicit size:

Table 2-2 Data Defaults Changed by -i2, -r8, -dbl

Default Type 

With -i2

With -r8 or -dbl

INTEGER INTEGER*2 INTEGER*8
LOGICAL LOGICAL*2 LOGICAL*8
REAL REAL*4 REAL*8
DOUBLE REAL*8 REAL*16
COMPLEX COMPLEX*8 COMPLEX*16
DOUBLE COMPLEX COMPLEX*16 COMPLEX*32

Do not combine -i2 with -r8 as this can produce unexpected results. REAL*16 and COMPLEX*32 are SPARC only.

With -dbl or -r8, INTEGER and LOGICAL are allocated the larger space indicated above. This is done to maintain the FORTRAN requirement that an integer item and a real item have the same amount of storage. However, with -r8 8 bytes are allocated but only 4-byte arithmetic is done. With -dbl, 8 bytes are allocated and full 8-byte arithmetic is done. In all other ways, -dbl and -r8 produce the same results. A disadvantage of using -r8 or -dbl is that it also promotes DOUBLE PRECISION data to QUAD PRECISION, possibly degrading performance.

Use of the more flexible -xtypemap option is preferred over the older -r8 and -dbl options. Both -dbl and -r8 have their -xtypemap equivalents:

The mapping integer:mixed indicates 8 byte integers but only 4 byte arithmetic.

There are two additional possibilities on SPARC:

-xtypemap=real:64,double:64,integer:mixed -xtypemap=real:64,double:64,integer:64

which map both default REAL and DOUBLE to 8 bytes, and should be preferable over using -r8 or -dbl.

Note that INTEGER and LOGICAL are treated the same, and COMPLEX is mapped as two REAL values. Also, DOUBLE COMPLEX will be treated the way DOUBLE is mapped.

Options -f or -dalign (SPARC only) force alignment of all 8, 16, or 32-byte data onto 8-byte boundaries. Option -dbl_align_all causes all data to be aligned on 8-byte boundaries. Programs that depend on the use of these options may not be portable.

See the Fortran User's Guide for details on these compiler options.