C 预处理器标记替换失败并出现解析错误
我在我的 C 程序中定义了以下宏:
#define ISE1 "cust_add"
#define ISE2 "cust_sub"
#define ise_inst(inst, a, b, c) \
asm volatile (
" " inst " %1, %2, %0 \n\t" \
: "=r" (c) \
: "r" (a), "r" (b) \
: "%g0" \
)
在主例程中,我使用以下参数调用宏:
ise_inst(ISE1, inp1, inp2, res);
理想情况下,预处理器应该扩展整个内容,以便我得到以下结果:
asm volatile (
" cust_add %1, %2, %0 \n\t"
: "=r" (res)
: "r" (inp1), "r" (inp2)
: "%g0"
);
Anyone知道我做错了什么吗?目前预处理器告诉我
错误:在字符串常量之前解析错误(@ line: " " inst " %1, %2, %0 \n\t" )
I have defined the following macros in my C program:
#define ISE1 "cust_add"
#define ISE2 "cust_sub"
#define ise_inst(inst, a, b, c) \
asm volatile (
" " inst " %1, %2, %0 \n\t" \
: "=r" (c) \
: "r" (a), "r" (b) \
: "%g0" \
)
In the main routine, I call the macro with the following parameters:
ise_inst(ISE1, inp1, inp2, res);
Ideally, the preprocessor should expand the whole thing so that I get the following result:
asm volatile (
" cust_add %1, %2, %0 \n\t"
: "=r" (res)
: "r" (inp1), "r" (inp2)
: "%g0"
);
Anyone an idea what I did wrong? At the moment the pre-processor tells me
error: parse error before string constant (@ line: " " inst " %1, %2, %0 \n\t" )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看起来您在
asm volatile(
行之后缺少\
行继续字符。Looks like you're missing a
\
line continuation character after theasm volatile(
line.除了缺少
\
之外,您的汇编指令还必须按如下所示进行字符串化:请注意
inst
之前的小#
。如果您随后使用ISE1
调用宏,则该宏将扩展为"ISE1"
。Besides the missing
\
, your assembler instruction must be stringified like this:Note the little
#
beforeinst
. If you then call your macro withISE1
this will expand to"ISE1"
.您是否忘记了
asm volatile (
后面的反斜杠字符 (\
) ?Didn't you forget about backslash character (
\
) afterasm volatile (
?