使用普通C预处理器宏,是否可以创建类似以下内容:
INIT_BASE(0x100) // init starting number
#define BASE_A GET_NEXT_BASE // equivalent to #define BASE_A 0x101
#define BASE_B GET_NEXT_BASE // 0x102
#define BASE_C GET_NEXT_BASE // 0x103
宏不能自动进行这种类型的计数,但是enum
s can.
#define INIT_BASE 0x100
enum foo
{
BASE_A = INIT_BASE + 1,
BASE_B,
BASE_C,
...
};
除非你really想要使用宏,您将必须手动进行计数:
#define INIT_BASE 0x100
#define BASE_A (INIT_BASE + 1) // equivalent to #define BASE_A 0x101
#define BASE_B (INIT_BASE + 2) // 0x102
#define BASE_C (INIT_BASE + 3) // 0x103
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)