是否有任何命名此类标识符的常规约定,以尽量减少冲突的可能性,并尽量减少它们可能产生的任何混淆?
HP_LIST
为什么不把符号放在同一个下面呢
HP_
前缀?例如前缀
HP__ZZQX_
,以区分有用和无用的符号。
注意:我参与过一个项目,其中一个共享库已经在使用(内部)
zzqx_
作为一个具体的东西,这里是你的源代码
hack around
##
要使用作为预处理器的前缀生成名称,请定义:
/* the hack is needed to force the LIST_NAME to be expanded.
automatically adds underscores. yes, it's ugly */
#define LIST_SYMBOL_1(n1,n2,n3) n1##_##n2##_##n3
#define LIST_SYMBOL_0(n1,n2,n3) LIST_SYMBOL_1(n1,n2,n3)
#define LIST_SYMBOL(pref,name) LIST_SYMBOL_0(LIST_NAME,pref,name)
/* give the name to the list. used by the LIST_SYMBOL(). */
#define LIST_NAME HP
/* Give the names and their respective lengths */
#define HP_LIST \
HP_ITEM(FRED, 4) \
HP_ITEM(GEORGE, 6) \
HP_ITEM(HARRY, 5) \
HP_ITEM(RON, 3) \
HP_ITEM(HERMIONE, 8) \
/* BLANK LINE REQUIRED TO ABSORB LAST BACKSLASH */
#define HP_ITEM(name, length) HPID_##name,
typedef enum { HP_LIST HP_ID_COUNT} HP_ID;
#undef HP_ITEM
#define HP_ITEM(name, length) LIST_SYMBOL(ZZQ,name)}; \
enum {LIST_SYMBOL(ZZQX,name)=LIST_SYMBOL(ZZQ,name)+(length)-1,
enum { HP_LIST HP_TOTAL_SIZE};
#undef HP_ITEM
#define HP_ITEM(name, length) LIST_SYMBOL(ZZQ,name),
const unsigned char hp_starts[] = { HP_LIST HP_TOTAL_SIZE};
#undef HP_ITEM
#include <stdio.h>
void main(void)
{
int i;
printf("ID count=%d Total size=%d\n",HP_ID_COUNT,HP_TOTAL_SIZE);
for (i=0; i<HP_ID_COUNT ; i++) /* bring the < back, SO is smart enough */
printf(" %2d=%3d/%3d\n", i, hp_starts[i], hp_starts[i+1]-hp_starts[i]);
printf("IDs are: \n");
#define HP_ITEM(name, length) printf(" %2d=%s\n",HPID_##name, #name);
HP_LIST
#undef HP_ITEMS
}
编辑1
. 我的首选方法是将数据放入适当的文本文件中,例如:
FRED
GEORGE
HARRY
RON
HERMIONE
那已经
巨大的