Fortran Programming Guide

Passing Data Arguments by Value

Call by value is available only for simple data with FORTRAN 77, and only by Fortran routines calling C routines. There is no way for a C routine to call a Fortran routine and pass arguments by value. It is not possible to pass arrays, character strings, or structures by value. These are best passed by reference.

Use the nonstandard Fortran function %VAL(arg) as an argument in the call.

In the following example, the Fortran routine passes x by value and y by reference. The C routine incremented both x and y, but only y is changed.

Table 11-12 Passing Simple Data Arguments by Value: FORTRAN 77 Calling C

Fortran 77 calls C 

REAL x, y

x = 1.

y = 0.

PRINT *, x,y

CALL value( %VAL(x), y)

PRINT *, x,y

END

-----------------------------------------------------------

void value_( float x, float *y)

{

printf("%f, %f\n",x,*y);

x = x + 1.;

y = y + 1.;

printf("%f, %f\n",x,*y);

}

-----------------------------------------------------------

Compiling and running produces output:

1.00000 0. x and y from Fortran

1.000000, 0.000000 x and y from C

2.000000, 1.000000 new x and y from C

1.00000 1.00000 new x and y from Fortran