Technical data
Cray Standard C/C++ Reference Manual
$ cc -c main.c
$ ftn -c ftnfctn.f
$ segldr main.o ftnfctn.o
$ a.out
$
In main: FLOAT1 = 1.6; FLOAT2 = 2.4
Calling FTNFCTN with arguments:
string = "C Character String"; logical = 1
IN FTNFCTN: FLOAT1 = 1.6; FLOAT2 = 2.4
ARGUMENTS: STR = "C Character String"; LOG = T
RETURNING FROM FTNFCTN WITH 123.4
Back in main: FTNFCTN returned 123.4
and changed the two arguments:
string = "New Fortran String"; logical = 0
$
9.3.8 Calling a Fortran Program from a Cray Standard C++ Program
The following example illustrates how a Fortran program can be called from a
Cray Standard C++ program:
#include <iostream.h>
extern "C" int FORTRAN_ADD_INTS(int *arg1, int &arg2);
main()
{
int num1, num2, res;
cout << "Start C++ main" << endl << endl;
//Call FORTRAN function to add two integers and return result.
//Note that the second argument is a reference parameter so
//it is not necessary to take the address of the
//variable num2.
num1 = 10;
num2 = 20;
cout << "Before Call to FORTRAN_ADD_INTS" << endl;
res = FORTRAN_ADD_INTS(&num1, num2);
cout << "Result of FORTRAN Add = " << res << endl << endl;
cout << "End C++ main" << endl;
}
136 S–2179–36










