The following table shows the correspondence between the data types available in IBM C/C++ Compilers, C Set ++ for AIX, Fortran, and Pascal. Several data types in C have no equivalent representation in Pascal or Fortran. Do not use them when programming for interlanguage calls. Blank table cells indicate that no matching data type exists.
Correspondence of Data Types among C, C++, Fortran, and Pascal | ||
C and C++ Data Types | Fortran Data Types | Pascal Data Types |
---|---|---|
char | CHARACTER | CHAR |
signed char | INTEGER*1 BYTE |
PACKED -128..127 |
unsigned char | LOGICAL*1 | PACKED 0..255 |
signed short int | INTEGER*2 | PACKED -32768..32767 |
unsigned short int | LOGICAL*2 | PACKED 0..65535 |
signed long int | INTEGER*4 | INTEGER |
unsigned long int | LOGICAL*4 | -- |
signed long long int | INTEGER*8 | -- |
unsigned long long int | LOGICAL*8 | -- |
float | REAL REAL*4 |
SHORTREAL |
double | REAL*8 DOUBLE PRECISION |
REAL |
long double | REAL*8 DOUBLE PRECISION |
REAL |
long double (with -qlongdouble or -qldbl128) | REAL*16 | -- |
structure of two floats | COMPLEX COMPLEX*4 |
RECORD of two SHORTREALS |
structure of two doubles | COMPLEX*16 DOUBLE COMPLEX |
RECORD of two REALS |
structure of two long doubles | COMPLEX*16 | -- |
struct | -- | RECORD (see notes below) |
enumeration | INTEGER*4 | Enumeration |
char[n] | CHARACTER*n | PACKED ARRAY[1..n] OF CHAR |
array pointer (*) to type | Dimensioned variable (transposed) | ARRAY |
pointer (*) to function | Functional Parameter | Functional Parameter |
structure (with -qalign=pack) | Sequence derived type | PACKED RECORD |
Special Treatment of Character
and Aggregate Data
Most numeric data types have counterparts across the three
languages. Character and aggregate data types require special
treatment:
VAR s: STRING(10);
is equivalent to:
struct { int length; char str [10]; };
where length contains the actual length of STRING.
Storage of a Two-Dimensional Array | |||
Storage Unit | C and C++ Element Name | Pascal Element Name | Fortran Element Name |
---|---|---|---|
Lowest | A[0][0] |
A[1,1] |
A(1,1) |
A[0][1] |
A[1,2] |
A(2,1) |
|
A[1][0] |
A[2,1] |
A(3,1) |
|
A[1][1] |
A[2,2] |
A(1,2) |
|
A[2][0] |
A[3,1] |
A(2,2) |
|
Highest | A[2][1] |
A[3,2] |
A(3,2) |
Interlanguage Calling Conventions
Using the Subroutine Linkage Conventions
in Interlanguage Calls
Sample Program: C Calling Fortran