Moving C++ bindings in gmpxx.h into a namespace

Marc Glisse marc.glisse at
Sun Jun 30 15:36:17 CEST 2013

On Sat, 29 Jun 2013, Sam Varshavchik wrote:

> Is there any interest in moving all the C++ bindings into their own 
> namespace, say gnu::mp?

Vaguely. Preferably at the same time as some other ABI-breaking changes.

> This is popular with many C++ dev libraries, like boost, for example.
> There are several advantages with doing that; mainly reducing the risk of 
> clashing with application's own symbols, or even with symbols from other 
> libraries that an app also links to.

The risk of clashing is very low. We currently use the old C namespacing 
technique of giving all names an application-specific prefix (plus we 
illegally put most names in the implementation namespace). Did you hit a 
particular issue or are you just suggesting it because it sounds good?

> I can prepare a patch to do that, if there's interest.
> Compatibility with existing code is trivial.

Binary compatibility is trivially broken. And some odd programs would also 
fail to compile (though that might be acceptable).

> Either provide a separate file that existing code can include, that 
> contains a grand total of three typedefs:
> typedef gnu::mp::mpz_class mpz_class;
> typedef gnu::mp::mpf_class mpf_class;
> typedef gnu::mp::mpq_class mpq_class;

You forgot gmp_randclass at least (and "using" is shorter than typedef).

> Or, for 100% source backwards compatibility, rename gmpxx.h to something 
> else, and have it declare everything in gnu::mp, and replace gmpxx.h with a 
> stub that includes the real file, and provides the three typedefs.

I'd probably import the names to the global namespace by default anyway, 
so no point complicating things too much.

Marc Glisse

More information about the gmp-devel mailing list