Hex Editor - Binary File Editing Software for Windows
Download Hex Editor Neo Hide this button

# Stringizing Operator

The number-sign or “stringizing” operator # converts macro parameters to string literals without expanding the parameter definition. It is used only with macros that take arguments. If it precedes a formal parameter in the macro definition, the actual argument passed by the macro invocation is enclosed in quotation marks and treated as a string literal. The string literal then replaces each occurrence of a combination of the stringizing operator and formal parameter within the macro definition.

White space preceding the first token of the actual argument and following the last token of the actual argument is ignored. Any white space between the tokens in the actual argument is reduced to a single white space in the resulting string literal. Thus, if a comment occurs between two tokens in the actual argument, it is reduced to a single white space. The resulting string literal is automatically concatenated with any adjacent string literals from which it is separated only by white space.

Further, if a character contained in the argument usually requires an escape sequence when used in a string literal (for example, the quotation mark (") or backslash () character), the necessary escape backslash is automatically inserted before the character.

#define ASSERT(condition, message) $assert(condition, message ": " #condition)

// …
struct A
{
    int a;
    ASSERT(a > 5, "a must be greater than 5");    
// The previous line will be replaced with $assert(a > 5, "a must be greater than 5" ": " "a > 5");
};