Re: C or C++

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxxxx>
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Assembler]     [Git]     [Kernel List]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [C Programming]     [Yosemite Campsites]     [Yosemite News]     [GCC Help]

  Powered by Linux