Technical data
Interlanguage Communication [9]
The Fortran program that is called from the Cray Standard C++ main function in
the preceding example is as follows:
INTEGER FUNCTION FORTRAN_ADD_INTS(Arg1, Arg2)
INTEGER Arg1, Arg2
PRINT *," FORTRAN_ADD_INTS, Arg1,Arg2 = ", Arg1, Arg2
FORTRAN_ADD_INTS = Arg1 + Arg2
END
The output from the execution of the preceding example is as follows:
Start C++ main
Before Call to FORTRAN_ADD_INTS
FORTRAN_ADD_INTS, Arg1,Arg2 = 10, 20
Result of FORTRAN Add = 30
End C++ main
9.4 Calling a C and C++ Function from an Assembly Language or Fortran Program
A C or C++ function can be called from Fortran or assembly language. One of
two methods can be used to call C functions from Fortran: the C interoperability
feature provided by the Fortran 2000 facility or the method documented in
this section. C interoperability provides a standard portable interoperability
mechanism for Fortran and C programs. Refer to
Fortran Language Reference
Manual, Volume 2 for more information about C interoperabillity. If you are using
the method documented in this section to call C functions from Fortran, keep in
mind the information in Section 9.3, page 126.
When calling a Cray Standard C++ function from Fortran or assembly language,
observe the following rules:
• The Cray Standard C++ function must be declared with extern "C"
storage class.
• The program must be linked with the CC(1) command.
The example that follows illustrates a Fortran program that calls a Cray Standard
C function. The Cray Standard C function being called, the commands required,
and the associated input and output are also included.
S–2179–36 137










