简体   繁体   English

内联asm是ANSI C标准的一部分吗?

[英]Is inline asm part of the ANSI C standard?

I always thought it was but many IDEs and syntax highlighting tools do not highlight ASM in C, but they always do with C++. 我一直认为这是因为许多IDE和语法突出显示工具没有在C中突出显示ASM,但它们总是使用C ++。 Is inline assembly part of the C standard (ANSII or ISO) or not? 内联汇编是否是C标准(ANSII或ISO)的一部分?

It's not in the ISO C standard (n1570 draft of C2011) as such, but mentioned in annex J (common extensions): 它不符合ISO C标准(C2011的n1570草案),但在附录J(常见扩展)中提到:

J.5.10 The asm keyword J.5.10 asm关键字

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

 asm ( character-string-literal ); 

Annex J is informative, not normative, so an implementation need not provide inline assembly, and if it does it's not prescribed in which form. 附件J是信息性的,而不是规范性的,因此实施不需要提供内联汇编,如果没有,则不以哪种形式规定。 But it's a widespread extension, though not portable since compilers do indeed implement it differently. 但它是一种广泛的扩展,虽然不可移植,因为编译器确实以不同方式实现它。

In the C++ standard (n3376 draft of the C++11 standard), it is mentioned in the body of the standard 在C ++标准(C ++ 11标准的n3376草案)中,它在标准正文中提到

7.4 The asm declaration [dcl.asm] 7.4 asm声明 [dcl.asm]

1 An asm declaration has the form 1 asm声明具有表单

asm-definition: ASM-定义:

 asm ( string-literal ) ; 

The asm declaration is conditionally-supported; asm声明是有条件支持的; its meaning is implementation-defined. 它的含义是实现定义的。 [ Note: Typically it is used to pass information through the implementation to an assembler. [注意:通常用于将信息通过实现传递给汇编程序。 — end note ] - 结束说明]

but also not mandatory, and with implementation-defined interpretation. 但也不是强制性的,并且具有实施定义的解释。

Contrary to popular belief, asm is in the C++ standard proper, but support for it is conditional. 流行的看法相反, asm C ++标准正确,但对它的支持是有条件的。 §7.4/1: §7.4/ 1:

An asm declaration has the form asm声明具有表单

asm-definition : asm-definition

 asm ( string-literal ) ; 

The asm declaration is conditionally-supported; asm声明是有条件支持的; its meaning is implementation- defined. 它的含义是实现定义的。

That said, the "conditionally supported" means you can't depend on a particular compiler supporting this at all. 也就是说,“有条件支持”意味着你根本不能依赖于支持这一点的特定编译器。 Microsoft (for one obvious example) uses an _asm keyword instead, but with a completely different syntax (the assembly language is enclosed in braces instead of a string literal). Microsoft(对于一个明显的示例)使用_asm关键字,但使用完全不同的语法(汇编语言用括号括起来而不是字符串文字)。

否 - 内联asm是一种常见的扩展,但非标准(并且通常由不同供应商实现不同)。

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

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