mixed_test


mixed_test, a C++ code which illustrates some issues in doing mixed language programming.

The world of bilingual programming

Because higher level languages end up as machine code, there is some reason to assume that you can write parts of a program in two different languages; what is not standard is the protocol for dealing with the differences in languages.

C++ supports (on purpose!) a scheme in which the names chosen by a user for various functions are automatically mangled, because it is assumed likely that the same name could be used in different namespaces, so C++ avoids ambiguity by constructing unique internal names when compiling. Unfortunately, this makes it very difficult for programs written in other languages to interact with a C++ code. One feature that can help is the use of the statement

        external "C" { (list of function declarations) }
      
in a C++ code in which name mangling is to be deactivated. The list of function declarations can be either the names of C routines to be called from this C++ routine, OR the names of internal C++ routines that are to be called by an external C routine.

Licensing:

The computer code and data files described and made available on this web page are distributed under the MIT license

Languages:

mixed_test is available in a C version and a C++ version and a FORTRAN90 version

Related Data and Programs:

C++_CALLS_C, C++ codes which call a C function.

C++_CALLS_F77, C++ codes which illustrate how a C++ main program can call a FORTRAN77 subroutine.

C++_CALLS_F90, C++ codes which illustrate how a C++ main program can call a FORTRAN90 subroutine.

F77_CALLS_C++, FORTRAN77 programs which illustrate how a FORTRAN77 program can call a C++ function.

F90_CALLS_C++, FORTRAN90 examples which illustrates how a FORTRAN90 program can call a C++ function.

Reference:

Source Code:

EX1 uses a C++ main program, and several C functions.


Last revised on 26 March 2020.