In C++ with -std=gnu++11 or later, strings that appear in asm
syntax—specifically, the assembler template, constraints, and
clobbers—can be specified as parenthesized compile-time constant
expressions as well as by string literals. The parentheses around such
an expression are a required part of the syntax. The constant expression
can return a container with data ()
and size ()
member functions, following similar rules as the C++26 static_assert
message. Any string is converted to the character set of the source code.
When this feature is available the __GXX_CONSTEXPR_ASM__
preprocessor
macro is predefined.
This extension is supported for both the basic and extended asm syntax.
#include <string> constexpr std::string_view genfoo() { return "foo"; } void function() { asm((genfoo())); }