public typedefs for gmp malloc/free types

Torbjorn Granlund tg at gmplib.org
Tue Aug 2 19:31:48 CEST 2011


Marc Glisse <marc.glisse at inria.fr> writes:

  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:
  
What is invalid about it, in "proper C++"?

  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.
  
Their types is defined, without a typedef in the manual:
http://gmplib.org/manual/Custom-Allocation.html

Please explain how new types for these function would improve things.
(There is a slight backward compatibility concern wrt adding types; old
GMP will not work as new ones.)

-- 
Torbjörn


More information about the gmp-discuss mailing list