|
|||||||||||
|
Technical Support On-Line Manuals C251 User's Guide |
C251 User's GuideStringize (#)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") stringizer(text) 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. | ||||||||||
|
|||||||||||