我正在阅读Hoard内存分配器的源代码,在gnuwrapper.cpp文件中,有以下代码:
#define CUSTOM_MALLOC(x) CUSTOM_PREFIX(malloc)(x)
"
CUSTOM_PREFIX(malloc)(x)
的意思是什么? CUSTOM_PREFIX
是一个函数吗?但作为一个函数,它没有被定义在任何地方。如果它是变量,那么我们怎么使用像var(malloc)(x)
这样的变量呢?
更多代码:
"#ifndef __GNUC__
#error "This file requires the GNU compiler."
#endif
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
#ifndef CUSTOM_PREFIX ==> here looks like it's a variable, so if it doesn't define, then define here.
#define CUSTOM_PREFIX
#endif
#define CUSTOM_MALLOC(x) CUSTOM_PREFIX(malloc)(x) ===> what's the meaning of this?
#define CUSTOM_FREE(x) CUSTOM_PREFIX(free)(x)
#define CUSTOM_REALLOC(x,y) CUSTOM_PREFIX(realloc)(x,y)
#define CUSTOM_MEMALIGN(x,y) CUSTOM_PREFIX(memalign)(x,y)