Is inline asm part of the ANSI C standard?

浪尽此生 提交于 2019-11-29 04:22:40

It's not in the ISO C standard (n1570 draft of C2011) as such, but mentioned in annex J (common extensions):

J.5.10 The asm keyword

1 The asm keyword may be used to insert assembly language directly into the translator output (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. 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

7.4 The asm declaration [dcl.asm]

1 An asm declaration has the form

asm-definition:

asm ( string-literal ) ;

The asm declaration is conditionally-supported; 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. §7.4/1:

An asm declaration has the form

asm-definition:

asm ( string-literal ) ;

The asm declaration is conditionally-supported; 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).

No - inline asm is a common extension, but non-standard (and quite often implemented differently by different vendors).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!