Specifications
42 Troubleshooting and Portability Issues Chapter 4
32035 Rev. 3.22 November 2007
Compiler Usage Guidelines for AMD64 Platforms
with the -Mupcase switch. This switch prevents the compiler from converting symbol names to
lower-case.
To match the underscore appended by the compiler to global symbol names in Fortran, use the
following function naming convention.
1. When calling a C/C++ function from Fortran, rename the C/C++ function by appending an
underscore.
2. When calling a Fortran function from C/C++, append an underscore to the Fortran function name
in the calling program.
Functions or Subroutines?
Fortran, C, and C++ define functions and subroutines differently. For a Fortran program calling a C or
C++ function, observe the following return value convention.
1. When the C or C++ function returns a value, call the value from Fortran as a function; when the C
or C++ function returns something other than a value, call the value as a subroutine.
2. When calling a Fortran function from C/C++, the call should return a similar type. For a list of
compatible types between the C/C+ and Fortran modules, refer to the PGI Compiler User’s
Guide.
The32-bit PGI compiler for Windows supports several different calling conventions. The nature of the
issues regarding interoperability of languages depends on the calling convention used. For additional
details please refer to the PGI Compiler User’s Guide.
Passing by Reference vs. Passing by Value
Fortran passes arguments by reference (i.e., the address of the argument is passed, rather than the
argument itself). C/C++ passes arguments by value, except for strings and arrays, which are passed by
reference. C/C++ provides the flexibility to work around these differences. Solving the parameter
passing differences generally involves intelligent use of the & and * operators in argument passing
when C/C++ calls Fortran and in argument declarations when Fortran calls C/C++.
For strings declared in Fortran as type CHARACTER, Fortran passes an argument representing the
length of the string to a calling function. On Linux systems, the compiler places the length
argument(s) at the end of the parameter list, following the other formal arguments and passes the
length argument by value, not by reference.
Passing Arrays
C/C++ arrays and Fortran arrays use different default initial array index values. By default, C/C++
arrays start at 0 and Fortran arrays start at 1. Adjust your array comparisons so that the second
element in a Fortran array is compared to the first element in a C/C++ array. Make similar
adjustments for other elements. If adjusting initial array index values is not satisfactory, declare your
Fortran arrays to start at zero.