Clive Page wrote:
> In addition, if you try to combine C++ with Fortran or another fine
> language you find that the combination is less portable,
Less portable than a single language implementation? This is self-
evident.
Or less portable that a similar C-Fortran implementation in C? If this
is true to any degree at all, it is not because of name mangling!
> because different
> systems have different conventions for name-mangling.
True, but all C++ implementations have the *SAME* convention for
**AVOIDING** name mangling:
extern "C" { declarations_not_to_be_mangled_go_here }
This facility allows C++ to declare functions that have to link up
correctly with C. This facility makes interlanguage calling problems
between C and C++ are extremely rare, but it also makes undesired name
mangling between Fortran and C++ easy to avoid.
(1) If C++ needs to call a Fortran routine, just wrap 'extern "C"'
around a working C prototype, and then call it in C++ the same way
you would in C.
Cray C example:
---------------
void SAXPY( const int * n, const double * alpha,
const double x[], const int * incx,
double y[], const int * incy );
...
SAXPY( &N, &a, xx, &xxstride, yy, &yystride );
Cray C++ example:
-----------------
extern "C" {
void SAXPY( const int * n, const double * alpha,
const double x[], const int * incx,
double y[], const int * incy );
}
...
SAXPY( &N, &a, xx, &xxstride, yy, &yystride );
If calling C++ from Fortran, just define a Fortran-callable C-like function
inside an 'extern "C"' block.
Cray C example:
---------------
C: void HEAP_CHECK( const int * level )
C: { malloc_check( *level ); }
Fortran: call heap_check( 5 );
Cray C++ example:
-----------------
C++: extern "C" {
C++: void HEAP_CHECK( const int * level )
C++: { malloc_check( *level ); }
C++: }
Fortran: call heap_check( 5 );
In short, C++ name mangling is easily avoided when it is not desired, so
it is really a non-issue in Fortran-C++ interface.
There *ARE* other, more serious interface issues, but they are generally
the same as the common Fortran-C interface issues.
-------- Cray Research --------- Roger Glover
-- A Silicon Graphics Company -- http://home.cray.com/~glover
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|