GMP, C++ and extern "C"

Emmanuel Thomé Emmanuel.Thome at
Mon Nov 20 16:23:20 CET 2006

On Mon, Nov 20, 2006 at 03:52:27PM +0100, Niels Möller wrote:
> I take it there's no chance of gmp supporting
>   extern "C" {
>     #include <gmp.h>
>   }
> ?

``extern "C"'' does not mean ``hey, disable C++ here'', it only mandates
C linkage.

C++ implementations (shall) always define __cplusplus, and understand the
extern "C" idiom.

> Then maybe adding C++ guards to all nettle include files is the
> easiest solution, after all.

Even when writing a C++-ignorant library, it is wise to do so,
indeed. Otherwise you'll encounter the difficulties you have here.

> Even though I really would have preferred to let those users who
> actually use (and know!) C++ handle all the C++ details.

It's more a ``be gentle with C++ users'' kind of detail. Nothing very

> The most time consuming part that change is not the editing of the
> header files, but the introduction of a C++ test case, and the
> corresponding changes to Makefiles and configure script to compile and
> use the test case only if a C++ compiler is available, and sort out
> which compiler is to be used for which files.


I don't see why you would have to to that. The 
	#ifdef	__cplusplus
	extern "C" {
	#ifdef  __cplusplus
works inconditionally, and allows your header to be used properly from
within a C++ program.



More information about the gmp-bugs mailing list