@str directive

The @str(x) directive expands into a double quoted string obtained by first macro expanding x then converting it to a double quoted string. The argument to the @str directive must always be enclosed in round brackets. The argument may itself contain round brackets as long as they pair up correctly (the preprocessor counts bracket tokens from a lexical scan to determine the extent of the argument). For example:

Before translationAfter translation
@def min(x,y) =
{
    @if(x < y) {x} @else {y}
}
const char* f()
{
    return @str(Minimum is min(3,4));
}





const char* f()
{
    return "Minimum is 3";
}

Non-printable characters, backslashes, single and double quote characters and so forth are escaped as required for string literals in C/C++ (see Table 1). For example:

Before translationAfter translation
@def a = @unstr('\a')
@def b = @unstr('\b')
@def f = @unstr('\f')
@def n = @unstr('\n')
@def r = @unstr('\r')
@def t = @unstr('\t')
@def v = @unstr('\v')
@def ff = @unstr('\xff')
@def z = @unstr('\0')
const char* s = @str(a b f n r t v ff z '\0' "w");










const char* s = "\a \b \f \n \r \t \v \xff \0 \'\\0\' \"w\"";

If the @str token and the subsequent left bracket token appear on the same line then all white space characters between the containing brackets are significant - i.e. are assumed to be part of the text to be represented as a C/C++ literal. For example:

Before translationAfter translation
const char* s = @str( 1

 2 );
const char* s = " 1\n\n 2 ";


Otherwise if the @str token and the subsequent left bracket token appear on different lines then the text to be converted is assumed to be an indented block. The position of the first nonwhitespace character defines the indent position of the block. The block is converted to a string literal without the white space characters to the left of this indent position and without the leading and trailing linefeeds (i.e. that appear just after the opening bracket and just before the closing bracket). Note that trailing white space characters on a given line are significant. For example:

Before translationAfter translation
const char* s =
    @str
    (
        abc
         def

        ghi
    );
const char* s =
    "abc\n def\n\nghi";