jburkardt

MIXED\ Mixed Language Programming {#mixed-mixed-language-programming align=”center”} ==========================


MIXED is a directory of C++ programs which illustrate some issues in doing mixed language programming.

The world of bilingual programming {#the-world-of-bilingual-programming align=”center”}

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++ program. One feature that can help is the use of the statement

        external "C" { (list of function declarations) }

in a C++ program 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: {#licensing align=”center”}

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

Languages: {#languages align=”center”}

MIXED language programming examples are available in a C version and a C++ version and a FORTRAN77 version and a FORTRAN90 version

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

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

C++_CALLS_F90, C++ programs 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: {#reference align=”center”}

Source Code: {#source-code align=”center”}

EX1 uses a C++ main program, and several C functions. Files you may copy include:

Examples and Tests: {#examples-and-tests align=”center”}

EX1_CC_CC uses the CC compiler for both the C++ and C codes. Files you may copy include:

EX1_G++_GCC uses the g++ compiler for the C++ and the gcc compiler for the C code. Files you may copy include:

You can go up one level to the C++ source codes.


Last revised on 04 January 2006.