【发布时间】:2013-09-19 13:39:22
【问题描述】:
当我尝试在宏中使用 ## 时出现错误,这是我尝试做的:
这样定义:
#define PORT 2
#define PIN 3
我希望预处理器生成:
PM2.3=1
当我这样调用宏时:
SetPort(PORT,PIN)
然后,我看到我可以在连接的同时进行替换 PORT 和 PIN,然后我认为我必须使用 2 个定义:
#define SetP2(PORT,PIN) PM##PORT.PIN = 1
#define SetPort(PORT,PIN) SetP2(PORT,PIN)
但我得到一个错误:
#define PIN 3 --> expected identifier before numeric constant
并发出警告:
SetPort(PORT,PIN) --> Syntax error
有什么想法吗?
【问题讨论】:
-
你是如何调用 gcc 的?
gcc -E <source.c>,还是别的什么?哪个版本的 gcc?
标签: gcc macros concatenation c-preprocessor