简体   繁体   English

这是由C99标准明确定义的吗?

[英]Is this well-defined by the C99 standard?

I've made the linker happy by defining main even though there's no main function in my program. 即使我的程序中没有main功能,我也通过定义main使链接器变得快乐。 Is this valid by the C99 standard? 这是否符合C99标准?

void foo()
{
    __asm__ (".globl main\n\n"
        "main:\n"
        "\txorl %eax, %eax\n"
        "\tret");
}

Live example 实例

不,C标准没有定义任何内联汇编的行为。

An implementation may provide __asm__ keyword, but only as an extension . 实现可以提供__asm__关键字,但仅作为扩展 In particular, C99 standard lists asm block within informative (non-normative) section J.5.10 The asm keyword : 特别是,C99标准列出了信息(非规范)部分中的asm块J.5.10 asm关键字

The asm keyword may be used to insert assembly language directly into the translator output (6.8). asm关键字可用于将汇编语言直接插入转换器输出(6.8)。 The most common implementation is via a statement of the form: 最常见的实现是通过以下形式的声明:

asm ( character-string-literal );

To be most precise, you program is not strictly conforming. 最确切地说,您的程序并不严格符合要求。 From §4/p5 Conformance (emphasis mine): 从§4/ p5 一致性 (强调我的):

A strictly conforming program shall use only those features of the language and library specified in this International Standard. 严格符合的程序 应仅使用本国际标准中规定的语言和库的特征 2) 2)

C中没有__asm__关键字,因此使用未在C中定义的关键字的简单事实意味着您的程序不严格符合。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM