I always thought it was but many IDEs and syntax highlighting tools do not highlight ASM in C, but they always do with C++. Is inline assembly part of the C standard (ANSII or ISO) or not?
-
1There is no such thing as ANSII. [ANSI](http://ansi.org/) is the American National Standards Institute, which issued the original C standard in 1989. All later versions of the standard (1990, 1999, 2011) have been issued by [ISO](http://www.iso.org/iso/home.html). – Keith Thompson Dec 13 '12 at 23:48
-
How could one possibly standardize ASM? C runs on all sorts of different processors, each with its own different assembly language. – Raymond Chen Dec 13 '12 at 23:50
-
1@RaymondChen: By standardizing only the syntax of the wrapper around the actual assembly code (see my answer for more details). – Jerry Coffin Dec 14 '12 at 00:05
3 Answers
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.

- 1
- 1

- 181,706
- 17
- 308
- 431
-
Oh, damned double-tagging. Didn't even notice it had a C++ tag too. – Daniel Fischer Dec 14 '12 at 00:08
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).

- 476,176
- 80
- 629
- 1,111
No - inline asm is a common extension, but non-standard (and quite often implemented differently by different vendors).

- 333,147
- 50
- 533
- 760