GMP内存管理功能出现Clang错误

Clang error on GMP memory management functions

本文关键字:Clang 错误 功能 内存 管理 GMP      更新时间:2023-10-16

我有一些使用GMP的代码,在g++下编译和运行良好。

...
// get ptrs to GMP memory management functions
void *(*alloc_func_ptr) (size_t);
void *(*free_func_ptr) (void *, size_t);
mp_get_memory_functions(&alloc_func_ptr, NULL, &free_func_ptr);
...

但是当我用最新的clang++编译它时,它抛出了这个错误

gmpxx_boost_serialization.h:127: error: no matching function for call to '__gmp_get_memory_functions'
mp_get_memory_functions(&alloc_func_ptr, NULL, &free_func_ptr);

其中mp_get_memory_functions是宏

#define mp_get_memory_functions __gmp_get_memory_functions
__GMP_DECLSPEC void mp_get_memory_functions (void *(**) (size_t),
                  void *(**) (void *, size_t, size_t),
                  void (**) (void *, size_t)) __GMP_NOTHROW;

clang为什么抱怨?

试着改变:

void *(*free_func_ptr) (void *, size_t);

:

void (*free_func_ptr) (void *, size_t);

根据声明,"mp_get_memory_functions"的第三个参数是函数指针的地址(指向返回"void"而不是"void *"的函数)

相关文章: