OON: Re: oon-digest V1 #62

From: lums@lsc.nd.edu
Date: Wed Mar 29 2000 - 21:02:12 EST


I assume you mean thoughts or opinions other than: "Aaah! Don't do
it!" :-)

As with any unnatural union, mixing C++ and F77 can be problematic to
do in a consistent and portable fashion. One usually has to spend
time in both the C++ compiler manual and the fortran compiler manual
to get it to work.

The two principle difficulties are

1) properly calling functions that are written in another language

   Here one has to deal with how functions are named with respect to
   another language (some compilers assume functions have underlines
   prepended or appended in various places), as well as the semantics
   of argument passing (pass by reference, pass by value). One has to
   use "C" linkage in C++ to be able to call a C++ function from
   another language. It is fairly straightforward to handle fortran
   pass by reference semantics with C++ reference semantics. Strings
   are a real pain. The 0/1 array indexing issue pops its head up
   from time to time.

2) getting the language-specific run-time stuff properly linked in

   I usually do this by using a C++ compiler as the linker and
   including the proper fortran libraries on the link line. Depending
   on your C++ compiler and/or fortran compiler, this may variously be
   -lf2c, -lg2c, -lF77, etc.

I have found in general that it pays to parameterize the things that
will vary from compiler to compiler either within the pre-processor
(function naming) or with automake/autoconf files (which libraries to
use).

In our last exciting episode "Csaba Zoltani" wrote:

> As an addendum to this thread, does anyone have any thoughts or opinions on
> calling C++ (routines or packages) from f77 codes and the dangers and
> difficulties involved?

Best Wishes,
Andrew Lumsdaine

--------------------- Object Oriented Numerics List --------------------------
* To subscribe/unsubscribe: use the handy web form at
http://oonumerics.org/oon/
* If this doesn't work, please send a note to owner-oon-list@oonumerics.org



This archive was generated by hypermail 2b29 : Wed Feb 20 2002 - 03:20:11 EST