预处理#define
我无法理解预处理器的工作原理以及 ##
在这个特定示例中代表
#include <stdio.h>
#define TEMP_KEY(type,Key) (TEMP_##type | Key)
enum TEMPKey_Type
{
TEMP_UNKNOWN = 0,
TEMP_SPECIAL ,
TEMP_UNICODE
};
enum Actual_Key
{
TEMP_RIGHT = TEMP_KEY(UNKNOWN,0x1),
TEMP_LEFT = TEMP_KEY(SPECIAL,0x1),
TEMP_UP = TEMP_KEY(UNICODE,0x1)
};
int main()
{
printf("\n Value of TEMP_RIGHT : %d ",TEMP_RIGHT);
printf("\n Value of TEMP_LEFT : %d ",TEMP_LEFT);
printf("\n Value of TEMP_UP : %d ",TEMP_UP);
return 0;
}
什么 #define TEMP_KEY(type,Key) (TEMP_##type | Key)
工作或在预处理过程中TEMP_##type
是如何替换的以及到底替换了什么?
I am unable to understand how the preprocessor works and what does the ##
stands for in this particular example
#include <stdio.h>
#define TEMP_KEY(type,Key) (TEMP_##type | Key)
enum TEMPKey_Type
{
TEMP_UNKNOWN = 0,
TEMP_SPECIAL ,
TEMP_UNICODE
};
enum Actual_Key
{
TEMP_RIGHT = TEMP_KEY(UNKNOWN,0x1),
TEMP_LEFT = TEMP_KEY(SPECIAL,0x1),
TEMP_UP = TEMP_KEY(UNICODE,0x1)
};
int main()
{
printf("\n Value of TEMP_RIGHT : %d ",TEMP_RIGHT);
printf("\n Value of TEMP_LEFT : %d ",TEMP_LEFT);
printf("\n Value of TEMP_UP : %d ",TEMP_UP);
return 0;
}
How does this#define TEMP_KEY(type,Key) (TEMP_##type | Key)
work or how and what exactly is TEMP_##type
replaced by during preprocessing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
“##”表示连接。因此
TEMP_RIGHT = TEMP_KEY(UNKNOWN,0x1)
变为TEMP_RIGHT = TEMP_UNKNOWN | 0x1,
(“TEMP_”和“UNKNOWN”连接在一起)The "##" means concatenate. Therefore
TEMP_RIGHT = TEMP_KEY(UNKNOWN,0x1)
becomesTEMP_RIGHT = TEMP_UNKNOWN | 0x1,
("TEMP_" and "UNKNOWN" are joined together)##
是#define 指令中的串联运算符。例如,TEMP_##type for TEMP_KEY(UNICODE,0x1) 调用生成以下代码:
##
is the concatenation operator in #define directives.For example, TEMP_##type for TEMP_KEY(UNICODE,0x1) call generates next code: