c - enum 和 define重复定义问题?
本文介绍了c - enum 和 define重复定义问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
/* Tokens. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
/* Put the tokens into the symbol table, so that GDB and other debuggers
know about them. */
enum yytokentype {
NOUN = 258,
PRONOUN = 259,
VERB = 260,
ADVERB = 261,
ADJECTIVE = 262,
PREPOSITION = 263,
CONJUNCTION = 264
};
#endif
/* Tokens. */
#define NOUN 258
#define PRONOUN 259
#define VERB 260
#define ADVERB 261
#define ADJECTIVE 262
#define PREPOSITION 263
#define CONJUNCTION 264
以上代码,是我从yacc自动生成的源码中复制出来的,不知道为什么 这里既然已经用enum定义了,为什么还要用宏定义下一下?
解决方案
Put the tokens into the symbol table, so that GDB and other debuggers know about them.
把Tokens放到符号表里,这样GDB和其他的调试工具就能识别它们。
简单的说,通过宏定义的Token,在程序运行时已经不存在,这样在调试工具里只能看到值而不能看到名称。而这里把Token通过enum放到符号表里,这样调试工具里就能把值转换成对于的名称了。
这篇关于c - enum 和 define重复定义问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文