From: elathan@phys.uoa.gr
To: Steven Shaw <steven_shaw@iprimus.com.au>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: mixing C/C++
Date: Tue, 25 Nov 2003 12:49:41 +0200 [thread overview]
Message-ID: <1069757381.3fc333c52bf2b@webmail.uoa.gr> (raw)
In-Reply-To: <200311251221.39488.steven_shaw@iprimus.com.au>
[-- Attachment #1: Type: text/plain, Size: 1070 bytes --]
Quoting Steven Shaw <steven_shaw@iprimus.com.au>:
> On Tuesday 25 November 2003 03:55, Elias Athanasopoulos wrote:
> > Apparently it is fine. The problem occures when I am wrapping
> > a class which inherits from multiple classes with virtual
> > functions.
>
> That should be fine too.
>
> > Any workarounds?
>
> Maybe you have C++ code with static members. If so you need to compile
main()
>
> with a C++ compiler. Here is an excellent resource:
>
> http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html
This is what I read and came to the above conclusion.
It states (32.9):
You can safely access a C++ object's data from a C function if the C++ class:
Has no virtual functions (including inherited virtual functions)
So I guess that is a problem. I verified that with the attached source file. Compile
the lib.cxx as a shared libfoo.so file and then try to call f->dump3() (f is struct
*Foo).
Also, I don't have main() in my project since it is a shared library.
Thanks for your help.
Regards,
Elias
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: lib.cxx --]
[-- Type: text/x-c++src; name="lib.cxx", Size: 716 bytes --]
#include <stdlib.h>
#include <stdio.h>
class Taz {
public:
Taz();
~Taz();
virtual void dump3(void);
};
class Bar {
public:
Bar();
~Bar();
virtual void dump2(void);
};
class Foo : public Bar, public Taz{
public:
Foo();
~Foo();
void dump(void);
};
Foo::Foo()
{
}
void Foo::dump(void)
{
printf("Foo Hello!\n");
}
Bar::Bar()
{
}
Bar::~Bar()
{
}
void Bar::dump2(void)
{
printf ("Bar Hello\n");
}
Taz::Taz()
{
}
void Taz::dump3(void)
{
printf ("Taz Hello!\n");
}
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();
}
extern "C"
void wrap_taz_dump3(Taz *t)
{
t->dump3();
}
next prev parent reply other threads:[~2003-11-25 10:49 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 [this message]
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
-- 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=1069757381.3fc333c52bf2b@webmail.uoa.gr \
--to=elathan@phys.uoa.gr \
--cc=linux-c-programming@vger.kernel.org \
--cc=steven_shaw@iprimus.com.au \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.