HP Fortran Programmer Guide (766160-001, March 2014)
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
CHP Fortran
char (array of)CHARACTER
char(array of)Hollerith (synonymous with CHARACTER)
charBYTE, LOGICAL(KIND=1), INTEGER(KIND=1)
shortLOGICAL(KIND=2)
shortINTEGER(KIND=2)
longor intLOGICAL, LOGICAL(KIND=4)
longor intINTEGER, INTEGER(KIND=4)
long longINTEGER(KIND=8)
floatREAL, REAL(KIND=4)
doubleDOUBLE PRECISION, REAL(KIND=8)
long doubleREAL(KIND=16)
structCOMPLEX, COMPLEX(KIND=4)
structDOUBLE COMPLEX, COMPLEX(KIND=8)
structderived type
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