need help on gfortran and C++
N.M. Maclaren
nmm1@cam.ac.uk
Wed Jan 11 12:53:00 GMT 2012
On Jan 11 2012, Tobias Burnus wrote:
>
>I assume that it is sufficient for you to change the name in the C++
>file. However, I want to point out that Fortran also provides means for
>better interoperability with C ["bind(C)"] - and thus with C++'s 'extern
>"C"', cf.
>http://gcc.gnu.org/onlinedocs/gfortran/Mixed_002dLanguage-Programming.html
A slight correction, which is more for us geeks than the OP :-)
Fortran does not formally support interoperability with C++ via that
route, and it isn't absolutely clear what C++ means by C linkage.
Both Fortran and C++ need to use a lot of created external names, and
have (moderately) advanced memory management and some error handling;
it isn't unlikely that those will conflict. It is also unclear
exactly which Fortran interoperability features will map to C enough
to interoperate with the ways that C++ maps its equivalent to C.
I raised this at WG5 and got the answer that I expected (i.e. that
Fortran does not formally support interoperability with C++).
The latter is easier - 7.5 [dcl.link] p.3 says "Every implementation
shall provide for linkage to functions written in the C programming
language". So far, so good. But there are some potential semantic
discrepancies that are swept under the carpet by the C++ standard,
such as IEEE 754 'support'. Anyone who relies on those and uses
Fortran/C++ interoperability had better prepare to be surprised!
I don't know of a clear and complete specification of how much of
this the GCC suite supports, but should be happy to cooperate with
any attempt to write one. If there IS one, I apologise, and should
appreciate a reference!
>Additionally, I want to point out that without using Bind(C) there might
>be additional issues - and differences between compilers; in particular,
>the way, "float"/"REAL" values and complex-number-returning functions
>are implemented, differs among compilers.
Yes. Very much so. In particular, complex-number-returning functions
are a minefield even with BIND(C) or between C++ and C and are hopeless
without it or 'extern "C"' :-(
Regards,
Nick Maclaren.
More information about the Gcc-help
mailing list