From: Glynn Clements <glynn@gclements.plus.com>
To: Shriramana Sharma <samjnaa@gmail.com>
Cc: Linux C Programming List <linux-c-programming@vger.kernel.org>
Subject: Re: C or C++
Date: Tue, 22 May 2007 19:10:56 +0100 [thread overview]
Message-ID: <18003.12848.409694.190317@cerise.gclements.plus.com> (raw)
In-Reply-To: <464B0AC1.2070501@gmail.com>
Shriramana Sharma wrote:
> > If it's likely to be useful to other libraries, there's a strong
> > incentive to use C, or at least to provide a C API (the standard
> > implementation of GLU is written in C++, although the public API only
> > uses C).
>
> Would it be enough if I ensure that the API header file does not contain
> any C++-only usages for such a library internally implemented in C++ to
> be linkable from a C program or library?
>
> Or would there be problems with the C linker not being able to resolve
> references from the C object code to C++ symbols in the library? (I hope
> I got that terminology correct.)
You can't link C code against C++ symbols.
If you want the library to be usable from C, the public interface must
consist of functions (not methods) which are declared with C linkage
(extern "C" ...). Those functions can call C++ code.
If you need to pass pointers to objects between C++ and C, you need to
cast them to/from something which is valid in C (e.g. "void *").
--
Glynn Clements <glynn@gclements.plus.com>
next prev parent reply other threads:[~2007-05-22 18:10 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-04 11:00 C or C++ Shriramana Sharma
2007-05-04 11:17 ` leslie.polzer
2007-05-04 13:46 ` Glynn Clements
2007-05-16 13:44 ` Shriramana Sharma
2007-05-22 18:10 ` Glynn Clements [this message]
-- strict thread matches above, loose matches on Subject: below --
2007-05-02 14:20 Shriramana Sharma
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=18003.12848.409694.190317@cerise.gclements.plus.com \
--to=glynn@gclements.plus.com \
--cc=linux-c-programming@vger.kernel.org \
--cc=samjnaa@gmail.com \
/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).