Calling C++ from Fortran

Here the situation with C is better considered separately from C++.

With C, the Fortran standard starting Fortran 2003 (about 18 years go) started providing a way to recognize the companion processor and defined the aspects toward interoperability. And practically, the conforming Fortran processors now strive to also interoperate with a companion C processor.

But with C++ and anything other language, they might as well not exist from a Fortran standard-conforming processor standpoint.

Thus when it comes to working with C++, it is back to pre-Fortran 2003 days of mixed-language programming, pretty much processor-dependent territory. It is better then for coders to stick to programs that are initiated with C++ processors (meaning no Fortran main program) and strive to interoperate such programs with the C processor per C++ semantics (extern “C” is part of this) and constrain Fortran to such a strict box toward C. On Windows OS in simple terms, this would mean Fortran code is in DLLs as much as feasible.

1 Like