linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Dari'o Mariani" <dmarian@fi.uba.ar>
To: Elias Athanasopoulos <elathan@pcmag.gr>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: mixing C/C++
Date: Mon, 24 Nov 2003 15:44:00 -0300	[thread overview]
Message-ID: <3FC25170.4050607@fi.uba.ar> (raw)
In-Reply-To: 20031124111050.GI1819@pcmag.gr

Hello:
   I think that the problem is in

extern "C"
Foo * wrap_foo_ctor()
{
	return new Foo();
}

In your C program you are using a C++ construct inside C, wich may work 
but the C compiler doesn't understand virtual functions so it might be 
confused there.

Elias Athanasopoulos wrote:
> Hello!
> 
> Consider:
> 
> class Bar {
> public:
>   Bar();
>   ~Bar();
> 
>   void dump2(void);
> };
> 
> class Foo : public Bar {
> public:
> 	Foo();
> 	~Foo();
> 
> 	void dump(void);
> };
> 
> extern "C"
> Foo * wrap_foo_ctor()
> {
> 	return new Foo();
> }
> 
> extern "C"
> void wrap_foo_dump(Foo *f)
> {
> 	f->dump();
> }
> 
> extern "C"
> void wrap_bar_dump2(Bar *b)
> {
> 	b->dump2();
> }
> 
> Now, I have a C program:
> 
> int main(void)
> {
> 	struct Foo *f;
> 
> 	f = wrap_foo_ctor();
> 	wrap_foo_dump(f);
> 	wrap_bar_dump2(f);
> }
> 
> which is working as -at least- I expect. Bar::dump2() is 
> called since Foo inherits from Bar.
> 
> However is it correct? I have a larger C++ project, which I'm
> creating wrappers for in C, and I get a segfault in a similar
> case (i.e. when I call a method *deep* inside the inheritence tree of a 
> class). 
> 
> Regards,



  parent reply	other threads:[~2003-11-24 18:44 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-11-24 11:10 mixing C/C++ Elias Athanasopoulos
2003-11-24 12:18 ` Steven Shaw
2003-11-24 17:55   ` Elias Athanasopoulos
2003-11-25  2:21     ` Steven Shaw
2003-11-25 10:49       ` elathan
2003-11-25 11:42         ` Glynn Clements
2003-11-25 13:12           ` elathan
2003-11-26  2:09             ` Glynn Clements
2003-12-02 18:22               ` Elias Athanasopoulos
2003-11-25 16:32         ` Steven Shaw
2003-11-24 18:44 ` Dari'o Mariani [this message]
  -- strict thread matches above, loose matches on Subject: below --
2003-11-08  9:30 Elias Athanasopoulos
2003-11-08 13:36 ` James Stevenson
2003-11-10 15:00 ` Matthew Studley
2003-11-10 17:37   ` Elias Athanasopoulos

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3FC25170.4050607@fi.uba.ar \
    --to=dmarian@fi.uba.ar \
    --cc=elathan@pcmag.gr \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).