Mail Archives: djgpp/1998/02/07/00:16:17
Mike McLean wrote:
>
> I've asked this question before, but forgot how the answer. How do I
> mix functions in a cpp file with those in a c file. I have some file
> routines in C++ that I'd like to use with my C program
It's very difficult to use C++-compiled code in a C program. C++
functions have mangled names, and expect things to be done differently
in general. There's almost certainly a way to do it but I couldn't tell
you what it is.
Using C object code in C++ programs is fairly simple, however. In the
header file that declares the C code, surround any code that must be
compatible with both C and C++ with the following directives:
#ifdef __cplusplus
extern "C" {
#endif
/* ... code ... */
#ifdef __cplusplus
}
#endif
This causes the code in the header file to be recognized as using a C
naming convention if it is included in a C++ program. All the DJGPP C
headers use it.
--
---------------------------------------------------------------------
| John M. Aldrich | "If 'everybody knows' such-and-such, |
| aka Fighteer I | then it ain't so, by at least ten |
| mailto:fighteer AT cs DOT com | thousand to one." |
| http://www.cs.com/fighteer | - Lazarus Long |
---------------------------------------------------------------------
- Raw text -