delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/01/12/04:02:22

Date: Tue, 12 Jan 1999 11:00:40 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Laurence Withers <lwithers AT lwithers DOT demon DOT co DOT uk>
cc: djgpp AT delorie DOT com
Subject: Re: Calling C++ functions from C functions: how?
In-Reply-To: <yeLbzQAKPlm2EAXL@lwithers.demon.co.uk>
Message-ID: <Pine.SUN.3.91.990112110022.15876Q-100000@is>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com

On Mon, 11 Jan 1999, Laurence Withers wrote:

> // obj.cc //////////////////////////////////////////////////////////////
> 
> // C++ function
> int cplusplus_tester_function(int a, int b)
> {
>     return (a + b);
> }
> 
> //
> // C wrapper
> //
> extern "C" {
>   int c_tester_function(int a, int b)
>   {
>       return cplusplus_tester_function(a, b);
>   }
> }
> 
> // end of obj.cc ///////////////////////////////////////////////////////

It should be emphasized that this technique will only work if both the
C wrapper and the C++ function it calls are defined in the same source
module.  Otherwise, you are back to square one.

- Raw text -


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