delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/02/07/00:16:17

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: C & C++ files
Date: Fri, 06 Feb 1998 18:59:11 -0500
Organization: Two pounds of chaos and a pinch of salt.
Lines: 36
Message-ID: <34DBA3CF.1ED2@cs.com>
References: <34DBA068 DOT CF62C468 AT primenet DOT com>
NNTP-Posting-Host: ppp244.cs.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019