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?
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With