www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/01/15/02:30:02

Sender: tim AT bashir DOT belgium DOT eu DOT net
Message-ID: <3A62A587.AC673A86@falconsoft.be>
Date: Mon, 15 Jan 2001 08:23:51 +0100
From: Tim Van Holder <tim DOT vanholder AT falconsoft DOT be>
Organization: Falcon Software NV
X-Mailer: Mozilla 4.76 [en] (X11; U; Linux 2.2.16-3 i686)
X-Accept-Language: en, nl-BE, nl
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
To: djgpp AT delorie DOT com
Subject: Re: Calling C++ functions from C (or using Bison with C++)
References: <3 DOT 0 DOT 1 DOT 32 DOT 20010112084816 DOT 006bc314 AT wingate>
<3 DOT 0 DOT 1 DOT 32 DOT 20010112084816 DOT 006bc314 AT wingate> <3 DOT 0 DOT 1 DOT 32 DOT 20010115131743 DOT 006b86ec AT wingate>
Reply-To: djgpp AT delorie DOT com

"Nimrod A. Abing" wrote:
> gets turned into a C program by the Bison program. Tim Van Holder's
> suggestion of using ``extern'' language declarations will not (and does
> not) compile because C doesn't recognize the extern "C" construct. Although
Ah, is THAT why it doesn't work? That's easy then: surround them with
#ifdef __cplusplus.

so:

[test.h]

#ifdef __cplusplus
extern "C"
#endif
void MyCplusPlusFunc(int);

or even:

#ifdef __cplusplus
# define CDECL extern "C"
#else
# define CDECL
#endif

CDECL int MyOtherCXXFunc(void);

This still won't allow overloads, but you can use wrappers for those
where
needed.
Oh, and don't count on pointer-to-functions supporting virtual
functions;
IIRC they're stored as offsets to the relevant entry in the virtual
table,
not as pointers to actual functions.
I'm not even sure you can be sure a C++ function without 'extern "C"'
will
have the same calling convention as a C function, so
pointers-to-functions
are not guaranteed to work (I think).

-- 
Tim Van Holder - Falcon Software N.V.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
This message was posted using plain text. I do not endorse any
products or services that may be hyperlinked to this message.

- Raw text -


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