对于以下代码,我们可以将'#define'视为 token 吗?
#define int char
main(){
int i=65; // i is initialized
printf("sizeof(i)=%d",sizeof(i));
}
最佳答案
ISO C 标准明确指出存在哪些标记,例如 c11 6.4
:
token:
keyword
identifier
constant
string-literal
punctuator
preprocessing-token:
header-name
identifier
pp-number
character-constant
string-literal
punctuator
each non-white-space character that cannot be one of the above
所以,不,#define
不是一个标记,它是两个预处理标记,#
和 define
标识符。
这是一个标识符,如 6.4.2.1
它的定义基本上为 [_A-Za-z][_A-Za-z0-9]*
.
关于我们可以将预处理器指令视为 token 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41583056/