C 中的 ASM 给出错误 -std=c99
我现在愿意使用 -std=c99
编译我的项目,但我遇到了一个我暂时无法理解的错误。 这一行:
my_type* td = ({ register kmy_type* arg0 asm("eax"); arg0; });
仅在 C99 中给我以下错误:
warning: ISO C forbids nested functions
error: syntax error before ‘asm’
error: ‘arg0’ undeclared (first use in this function)
error: (Each undeclared identifier is reported only once
error: for each function it appears in.)
warning: ISO C forbids braced-groups within expressions
欢迎任何线索来帮助我理解这意味着什么。 我没有写这行,我也不确定它的目的是什么。
I'm now willing to compile my project with -std=c99
and I'm facing an error I'm not understanding for the moment. This line :
my_type* td = ({ register kmy_type* arg0 asm("eax"); arg0; });
gives me the following error only in C99 :
warning: ISO C forbids nested functions
error: syntax error before ‘asm’
error: ‘arg0’ undeclared (first use in this function)
error: (Each undeclared identifier is reported only once
error: for each function it appears in.)
warning: ISO C forbids braced-groups within expressions
Any clues are welcome to help me understanding what this means. I didn't write this line and I'm also not sure to understand what is its purpose.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
该行
应该在 eax 寄存器中获取一个值,该值被解释为指向 td 变量的指针。 然而,它使用了大量的 GNU 扩展,特别是语句表达式和
asm
(显式寄存器分配)的使用。 我建议您切换到 -std=gnu99 (或任何名称)。 否则,您可能想使用双下划线(例如asm
->__asm
)或__extension__
关键字,但我不这样做知道它在 c99 模式下是否有帮助。编辑:我刚刚尝试过,只需将
asm
更改为__asm
即可。The line
should get a value in the
eax
register, interpreted as a pointer, intotd
variable. However, it uses lots of GNU extensions, particularly statement expressions and this use ofasm
(explicit register allocation). I'd suggest you to switch to -std=gnu99 (or whatever it's called). Otherwise, you might want to play with double underscores (eg.asm
->__asm
) or the__extension__
keyword, but I don't know if it'll help in c99 mode.Edit: I just tried it and simply changing
asm
to__asm
works.asm()
似乎不适用于-std=c99
。 在我看来,这是一个坏主意,因为该标准实际上建议编译器支持asm()
关键字,但这不是强制性的。我建议您改用
-pedantic
。asm()
doesn't seem to work with-std=c99
. It's a bad idea in my opinion, since the standard actually suggests that compilers support anasm()
keyword, but it isn't mandatory.I suggest that you use
-pedantic
instead.问题不在于asm,看起来像是它的arg0
The problem there is not asm, looks like its arg0