8 Calling C routines from HP Fortran

This section describes language differences between C and HP Fortran that affect calling C routines from an HP Fortran program. This includes the following topics:

Data types Calling C routines from HP Fortran 182 Chapter 8

Argument-passing conventions

Case sensitivity

Arrays

C strings

File handling

Sharing data

Data types

Table 8-1 lists the corresponding data types for HP Fortran and C when compiled as 32-bit applications.

Table 32 Data type correspondence for HP Fortran and C

HP Fortran

C

 

 

CHARACTER

char (array of)

 

 

Hollerith (synonymous with CHARACTER)

char(array of)

 

 

BYTE, LOGICAL(KIND=1), INTEGER(KIND=1)

char

 

 

LOGICAL(KIND=2)

short

 

 

INTEGER(KIND=2)

short

 

 

LOGICAL, LOGICAL(KIND=4)

longor int

 

 

INTEGER, INTEGER(KIND=4)

longor int

 

 

INTEGER(KIND=8)

long long

 

 

REAL, REAL(KIND=4)

float

 

 

DOUBLE PRECISION, REAL(KIND=8)

double

 

 

REAL(KIND=16)

long double

 

 

COMPLEX, COMPLEX(KIND=4)

struct

 

 

DOUBLE COMPLEX, COMPLEX(KIND=8)

struct

 

 

derived type

struct

 

 

Using the +DA2.0Woption to compile HP Fortran programs in 64-bit mode has no effect on Fortran data types; see “Compiling in 64-bit mode” (page 63). However, it does change the sizes of some C data types. If your program calls functions written in C and is compiled in 64-bit mode, you should be aware of the size discrepancies and either promote individual data items or recompile with the +autodbloption to promote all default integer, real, and logical items to 64-bits.

Table 8-2 shows the differences between the corresponding data types in HP Fortran and C when compiling in 32-bit mode and in 64-bit mode. Table 8-3 shows the differences when the Fortran program is compiled with the +autodbloption. Notice that Fortran data items that are explicitly sized (for example, INTEGER*4) stay the same size regardless of whether they are compiled in 32-bit mode, in 64-bit mode, or with the +autodbloption.

110 Calling C routines from HP Fortran