Operating System - OpenVMS
1827452 Members
3899 Online
109965 Solutions
New Discussion

Re: C++ objects in Fortran77

 
Paul Vinders
Occasional Contributor

C++ objects in Fortran77

Hi everybody,

does anyone know how to use a C++ class in Fortran77? And how to call C++ methods in Fortran77?

Sincerely,
Paul Vinders
2 REPLIES 2
Robert Gezelter
Honored Contributor

Re: C++ objects in Fortran77

Paul,

One way (which I implemented for a client product) is to write a C-calling convention set of binding routines.

How easy this is depends on what precisely the interface specification is.

- Bob Gezelter
John Gillings
Honored Contributor

Re: C++ objects in Fortran77

Paul,

Generic answer... on OpenVMS any language can call routines written in any other language. You just need to make sure the arguments match in position, data type and passing mechanism. For complex data types, there may be compatibility issues between languages, so it's best to keep interfaces as simple as possible. You may also have to force specific mechanisms using FORTRAN built-in functions %VAL, %REF & %DESCR

For C++ you have the added complication of name mangling - compiler generated names to keep them unique and fit within the name length limits of the OpenVMS linker. You can specify a C++ global entity has a non-mangled name, or, as Bob suggests, write a jacket interface with non-mangled names.

If you're really keen, you can determine the mangled names from the librarian, linker map or mangler/demangler utilities and call them directly, but the Fortran side will be rather cryptic!
A crucible of informative mistakes