C 中的 ASM 给出错误 -std=c99

发布于 2024-07-17 08:16:35 字数 540 浏览 5 评论 0原文

我现在愿意使用 -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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

沩ん囻菔务 2024-07-24 08:16:36

该行

my_type* td = ({ register my_type* arg0 asm("eax"); arg0; });

应该在 eax 寄存器中获取一个值,该值被解释为指向 td 变量的指针。 然而,它使用了大量的 GNU 扩展,特别是语句表达式和 asm(显式寄存器分配)的使用。 我建议您切换到 -std=gnu99 (或任何名称)。 否则,您可能想使用双下划线(例如 asm -> __asm)或 __extension__ 关键字,但我不这样做知道它在 c99 模式下是否有帮助。

编辑:我刚刚尝试过,只需将 asm 更改为 __asm 即可。

The line

my_type* td = ({ register my_type* arg0 asm("eax"); arg0; });

should get a value in the eax register, interpreted as a pointer, into td variable. However, it uses lots of GNU extensions, particularly statement expressions and this use of asm (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.

凉月流沐 2024-07-24 08:16:36

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 an asm() keyword, but it isn't mandatory.

I suggest that you use -pedantic instead.

小伙你站住 2024-07-24 08:16:36

问题不在于asm,看起来像是它的arg0

The problem there is not asm, looks like its arg0

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文