[CMake] FORTRAN name mangling

Arjen Markus Arjen.Markus at deltares.nl
Tue Jan 12 03:04:01 EST 2016


> Exactly, that is the whole point of the standardized `ISO_C_BINDING` module and C interop being added to the Fortran 2003 standard. No more ugly guess work, hackery, etc.

> AFAIK, there is pretty good support for this among compiler vendors, so long as you have a recent release.

> Even as far back as about five years ago, all 10 compilers surveyed by Ian Chivers and Jane Sleightholme supported C interoperability.  And now there are at least four compilers that even support the _additional_ C interoperability features in the draft Fortran 2015 standard: the IBM, Cray, Intel, and GNU compilers.  C interoperability appears to be one of the first things every compiler team tackles from a new standard.

> Anyone with access to ACM Fortran Forum will benefit from consulting the standards-support survey that Ian and Jane have published in almost every issue for roughly a decade or so.  Standards support in  Fortran compilers is not quite where it needs to be, but it's much better than it was even just a couple of years ago. Great strides have been taken.

Just to chime in here, in the PLplot project (plplot.sf.net) we are currently reimplementing the Fortran interface to the plotting routines that have been implemented in C. The previous version took advantage of all Fortran 90/95 features, such as function overloading and assumed-shape arrays to avoid the extra arguments needed to tell the plotting routines how many elements there are. This required quite a lot of C code, as the naming conventions/name mangling had to be handled on the C side.

The new set-up however uses the ISO_C_BINDING features to the fullest extent. The benefits of this new set-up are plenty:

- We can support single and double precision versions of the routines in one library, whereas before we had to rely on the Fortran programs using the same precision as the C library. This could have been done with just the Fortran 90/95 features too - just a matter of progressive insight.

- Almost all C code has been eliminated as matching the names of the routines can now be done on the Fortran side. The advantage of that is that the Fortran compiler is completely responsible for this, rather than a set of confusing C macros the details of which depend on the Fortran compiler.

Of course, this means that you have to have the ability to adjust the Fortran code, but for a given library, you could simply write a Fortran interface layer that uses the ISO_C_BINDING features instead of a C one.

Regards,

Arjen
DISCLAIMER: This message is intended exclusively for the addressee(s) and may contain confidential and privileged information. If you are not the intended recipient please notify the sender immediately and destroy this message. Unauthorized use, disclosure or copying of this message is strictly prohibited. The foundation 'Stichting Deltares', which has its seat at Delft, The Netherlands, Commercial Registration Number 41146461, is not liable in any way whatsoever for consequences and/or damages resulting from the improper, incomplete and untimely dispatch, receipt and/or content of this e-mail.


More information about the CMake mailing list