Language mixing - Argument passing


Simple scalar arguments are passed "by value" in C and "by reference" in FORTRAN so some argument manipulation is normally required to call a FORTRAN routine from C and vice versa. Call by reference can be used in C++ making it simpler to mix C++ and FORTRAN than to mix C and FORTRAN.

FORTRAN:

      CALL VADD(C1,C2,C3,2)

Call FORTRAN VADD from C:

extern void vadd_( const double [], const double[],
                  double[], const unsigned * );

int d=2;

   vadd_( C1, C2, C3, &d );

Call FORTRAN VADD from C++:

extern "C" void vadd_( const double [], const double [],
                      double [], const unsigned & );

   vadd_( C1, C2, C3, 2 );

Arrays are called by reference in C, C++ and FORTRAN so no problem (but see strings below).