Language mixing - Argument passing


C/C++ use NULL-terminated character arrays to represent strings. Strings are handled in a system-dependent way with FORTRAN. Typically FORTRAN compilers on Unix systems pass strings as a character array (without NULL-termination) and a hidden trailing argument containing the string length. With VMS things get really horrible.

FORTRAN:

      CALL PVEC( C3,' = ',C1,' + ',C2 )

Call FORTRAN PVEC from C/C++ (Unix):

extern void pvec_( const double [], const char [],
                   const double [], const char [],
                   const double[] );

   pvec_( C3, " = ", C1, " + ", C2, 3, 3 );

Call FORTRAN PVEC from C/C++ (VMS):

extern ["C"] void pvec_( const double [], string,
                   const double [], string,
                   const double[] );

   pvec_( C3, mkstr(" = "), C1, mkstr(" + "), C2 );

Although horrible, this can be hidden by using suitable inlined jacket procedures in C++ (or macros/functions in C).