【发布时间】:2019-04-16 06:26:26
【问题描述】:
我正在编写一些我想多次使用的代码,其中函数和变量名称略有不同。我想用宏替换部分函数和变量名。 gcc filename.c -E 表明没有进行替换。我该如何纠正这个问题?
这是替换之前文件中的一些代码:
#define _CLASS Object
#define POOLLEVEL1 1024
#define POOLLEVEL2 1024
typedef struct {
int Self;
int Prev;
int Next;
int In_Use;
//----data----//
//----function pointers----//
} Object;
_CLASS* _CLASS_Pool[POOLLEVEL1] = { 0 };
//Note on POOLLEVEL1, POOLLEVEL2: _CLASS_Pool[] is an array of pointers to arrays of type _CLASS. The number of objects in these arrays is LEVEL2, the maximum number of arrays of type object is LEVEL1; The arrays of type object are allocated when needed.
int _CLASS_Available_Head = -1;
int _CLASS_Available_Tail = -1;
//Start and finish of list of available objects in pool.
// More follows
【问题讨论】:
-
“表明没有进行替换” - 源代码在预处理之前看起来如何?
-
这是预处理前后代码的样子。我希望预处理器用 'Object' 替换 '_CLASS' 的实例
标签: c replace macros c-preprocessor