0% found this document useful (0 votes)
4 views2 pages

Basic Asm 4

In C++11 and later, strings in asm syntax can be specified as compile-time constant expressions instead of just string literals. This allows for more flexibility in defining strings used in inline assembly, with the requirement of parentheses around the expression. The feature is supported in both basic and extended asm syntax, and the __GXX_CONSTEXPR_ASM__ macro is predefined when available.

Uploaded by

Azamet Tarkan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Basic Asm 4

In C++11 and later, strings in asm syntax can be specified as compile-time constant expressions instead of just string literals. This allows for more flexibility in defining strings used in inline assembly, with the requirement of parentheses around the expression. The feature is supported in both basic and extended asm syntax, and the __GXX_CONSTEXPR_ASM__ macro is predefined when available.

Uploaded by

Azamet Tarkan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Next: Controlling Names Used in Assembler Code, Previous: Constraints for asm Operands, Up:

How to Use Inline Assembly Language in C Code [Contents][Index]

6.11.4 C++11 Constant Expressions instead of String Literals

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()));
}

You might also like