Keil Logo

Stringize (#)

The stringize or number-sign operator ('#'), when used within a macro definition, converts a macro parameter into a string constant. This operator may be used only in a macro that has a specified argument or parameter list.

When the stringize operator immediately precedes the name of one of the macro parameters, the parameter passed to the macro is enclosed within quotation marks and is treated as a string literal. For example:

#define stringizer(x)  printf (#x "\n")


This example results in the following actual output from the preprocessor:

printf ("text\n")

The expansion shows that the parameter is converted literally as if it were a string. When the preprocessor stringizes the x parameter, the resulting line is:

printf ("text" "\n")

Because strings separated by whitespace are concatenated at compile time, these two strings are combined into "text\n".

If the string passed as a parameter contains characters that should normally be literalized or escaped (for example, " and \), the required \ character is added automatically.

  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.