Bringing Fortran, C and C++ together

(2014-11-13)

Most compiler suites come today with the (not so) holy trinity of widespread compiled languages: Fortran, C and C++. Here are some remarks on using them together.

Disclaimer: On the Fortran side, this is mostly about Fortran77/95. Modern Fortran has more tools for this. So, this information might be useful for interfacing legacy code.

Ways of passing of data to subroutines

void abc(int x) /* by value*/
void abc(int *x) /* by address*/
c      passing a scalar:
       subroutine abc(x)
	   integer x

c      passing an array: 
       subroutine abc(x)
	   integer x
	   dimendsion x(10)
void abc(int x) // by value
void abc(int *x) // by address
void abc(int &x) // by reference

So, the lowest common denominator between C,C++ and Fortran is passing by address, and the lowest common denominator between C and C++ is passing by address or by value.

Name mangling

Linking together compilation units from different languages creates the need to identify "linker symbols" created by the different languages from the same name in the source code. The same name shows up differently.

The name abc is transformed to

How to solve: