public typedefs for gmp malloc/free types

Marc Glisse marc.glisse at
Mon Aug 1 15:39:52 CEST 2011


the following is a common use of gmp:

       void (*gmp_free) (void *, size_t);
       mp_get_memory_functions (NULL, NULL, &gmp_free);
       (*gmp_free) (str, strlen (str) + 1);

which is valid in C, compiles with g++, but is invalid in C++ proper. For 
this reason, we have in gmpxx.h:

extern "C" {
   typedef void (*__gmp_freefunc_t) (void *, size_t);

so we can declare:

       __gmp_freefunc_t gmp_free;

Now, I have to introduce this same fix in CGAL and in GCC. I believe it 
would be good if gmp provided an official, documented typedef for the 
types of the malloc/realloc/free functions it uses.

Possibly gmp_malloc_t/gmp_realloc_t/gmp_free_t, but I really don't care 
about the name.

What do you think?

Marc Glisse

PS: I'm unhappy about the order of the arguments to realloc, but that boat 
has sailed long ago.

More information about the gmp-discuss mailing list