Oracle® Solaris Studio 12.4: C User's Guide

Exit Print View

Updated: March 2015
 
 

2.14.2 __asm Keyword

The __asm keyword (note the initial double-underscore) is a synonym for the asm keyword. The compiler will issue a warning for uses of the asm keyword when -pedantic is in effect. Use __asm to avoid these warnings. The __asm statement has the form:

__asm("string");

where string is a valid assembly language statement.

The statement emits the given assembler text directly into the assembly file. A basic asm statement declared at file scope, rather than function scope, is referred to as a global asm statement. Other compilers refer to this as a toplevel asm statement.

Global asm statements are emitted in the order they are specified, retaining their order relative to each other and maintaining their position relative to surrounding functions.

At higher optimization levels, the compiler may remove functions that it has determined are not referenced. Because the compiler cannot evaluate which functions are referenced from within global assembly language statements, they might be removed inadvertently.

Note that extended asm statements, those which provide a template and operand specifications, are not allowed to be global. __asm and __asm__ are synonyms for the asm keyword and can be used interchangeably.

When specifying architecture-specific instructions it might be necessary to specify an appropriate -xarch value to avoid compilation errors.