Table 11–2 summarizes the data sizes and default alignments for Fortran 95 data types compared with C. It assumes no compilation options affecting alignment or promoting default data sizes are applied. Note the following:
C data types int, long int, and long are equivalent (4 bytes) in a 32-bit environment. However, in a 64-bit environment, long and pointers are 8 bytes. This is referred to as the LP64 data model.
REAL*16 and COMPLEX*32, in a 64-bit SPARC environment and when compiling with any -m64 option, are aligned on 16-byte boundaries.
Alignments marked 4/8 indicate that alignment is 8-bytes by default, but on 4-byte boundaries in COMMON blocks. The maximum default alignment in COMMON is 4-bytes. 4/8/16 indicates alignments on 16-byte boundaries when compiling with -m64 option.
REAL(KIND=16), REAL*16, COMPLEX(KIND=16), COMPLEX*32, are only available on SPARC platforms.
The elements and fields of arrays and structures must be compatible.
You cannot pass arrays, character strings, or structures by value.
You can pass arguments by value from a Fortran 95 routine to a C routine by using %VAL(arg) at the call site. You can pass arguments by value from C to Fortran 95 provided the Fortran routine has an explicit interface block that declares the dummy argument with the VALUE attribute.
Components of numeric sequence types are aligned the same way as common blocks, and are also affected by the -aligncommon option.A numeric sequence type is a sequence type where all the components are of type default integer, default real, double-precision real, default complex, or default logical, and are not pointers.
Components of data types that are not numeric sequence types are aligned on natural alignments in most cases, except QUAD variables. For quad-precision variables, the alignment is different between 32–bit and 64–bit SPARC platforms.
Components of VAX structures and data types defined with the BIND(C) attribute always have the same alignment as C structures on all platforms.
Fortran 95 Data Type |
C Data Type |
Size |
Alignment |
|
---|---|---|---|---|
BYTE x |
char x |
1 |
1 |
|
CHARACTER x |
unsigned char x ; |
1 |
1 |
|
CHARACTER (LEN=n) x |
unsigned char x[n] ; |
n |
1 |
|
COMPLEX x |
struct {float r,i;} x; |
8 |
4 |
|
COMPLEX (KIND=4) x COMPLEX (KIND=8) x COMPLEX (KIND=16) x (SPARC) |
struct {float r,i;} x; struct {double dr,di;} x; struct {long double, dr,di;} x; |
8 16 32 |
4 4/8 4/8/16 |
|
DOUBLE COMPLEX x |
struct {double dr, di;} x; |
16 |
4/8 |
|
DOUBLE PRECISION x |
double x ; |
8 |
4 |
|
REAL x |
float x ; |
4 |
4 |
|
REAL (KIND=4) x REAL (KIND=8) x REAL (KIND=16) x (SPARC) |
float x ; double x ; long double x ; |
4 8 16 |
4 4/8 4/8/16 |
|
INTEGER x |
int x ; |
4 |
4 |
|
INTEGER (KIND=1) x INTEGER (KIND=2) x INTEGER (KIND=4) x INTEGER (KIND=8) x |
signed char x ; short x ; int x ; long long int x; |
1 2 4 8 |
4 4 4 4 |
|
LOGICAL x |
int x ; |
4 |
4 |
|
LOGICAL (KIND=1) x LOGICAL (KIND=2) x LOGICAL (KIND=4) x LOGICAL (KIND=8) x |
signed char x ; short x ; int x ; long long int x; |
1 2 4 8 |
4 4 4 4 |