MIXED contains some simple examples of mixed language program. In particular, this directory considers situations in which the main program is written in C++.
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.
MIXED language programming examples are also available for cases in which the main routine is written in C and FORTRAN77 and FORTRAN90.
EX1 uses a C++ main program, and several C functions. Files you may copy include:
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.