itaps-parallel Fortran name mangling issues

Mark Miller miller86 at llnl.gov
Wed Nov 12 14:33:11 CST 2008


Hi All,

Regarding the Fortran name mangling issue...

There is a support macro, FC_FUNC, that is often used to handle fortran
name mangling.

For a library with say 3 functions

   MyLibInit(int argc, char **argv);
   MyLibFinal(void);
   MyLibWork(int c, float *f);

your header file would have something like...

#if defined(FC_FUNC)
FC_FUNC(mylibinit,MYLIBINIT)
FC_FUNC(mylibfinal,MYLIBFINAL)
FC_FUNC(mylibwork,MYLIBWORK)
#endif

The FC_FUNC macro handles upper/lower case and leading/trailing
underscores for Fortran name mangling. 

The FC_FUNC macro winds up getting defined by something; Autoconf's
configure script does some work to define it. Or, like Onkar suggests,
you can define some logic ahead of time to set whatever FC_FUNC does
using logic like so...

#ifdef AIX
#define FC_FUNC(lowFunc,UPfunc) _lowFunc
#elif GFORTRAN
#define FC_FUNC(lowFunc,UPfunc) UPfunc
#elif ...
..
.

The only issue I see with this approach is that you need to have defined
ahead of time all the possible #ifdef #elif cases above and whenever you
go to a new machine, then you'll have to re-visit this logic. So, I like
the approach where Autconf's configure is used to set FC_FUNC.

Finally, whatever FC_FUNC is set to, it MUST match the actual name
mangling used by whatever fortran compiler is being used to compile the
code. So, it is not just a matter of everyone agreeing on an
implementation for FC_FUNC. FC_FUNC must also address whatever name
mangling is being used by a given fortran compiler on a given platform
when the code is getting compiled. For that reason, I think the best
approach is the Autoconf approach.

Mark


-- 
Mark C. Miller, Lawrence Livermore National Laboratory
email: mailto:miller86 at llnl.gov
(M/T/W) (925)-423-5901 (!!LLNL BUSINESS ONLY!!)
(Th/F)  (530)-753-8511 (!!LLNL BUSINESS ONLY!!)




More information about the itaps-parallel mailing list