Microsoft KB Archive/57949

= INFO: Use of the Stringizing Operator (#) in Macros =

Article ID: 57949

Article Last Modified on 12/11/2003

-

APPLIES TO


 * Microsoft Visual C++ 1.0 Professional Edition
 * Microsoft Visual C++ 1.5 Professional Edition
 * Microsoft Visual C++ 2.0 Professional Edition
 * Microsoft Visual C++ 4.0 Standard Edition
 * Microsoft Visual C++ 5.0 Enterprise Edition
 * Microsoft Visual C++ 6.0 Enterprise Edition
 * Microsoft Visual C++ 5.0 Professional Edition
 * Microsoft Visual C++ 6.0 Professional Edition
 * Microsoft Visual C++ 6.0 Standard Edition

-



This article was previously published under Q57949





SUMMARY
In Microsoft C for MS-DOS and Windows NT, when you are writing a preprocessor macro that takes an argument that must appear in quotation marks, you can use the # sign to expand the argument. One implementation of this preprocessor directive is the use of printf in the macro. The following code demonstrates an example:

Sample Code

 * 1) define PR(fmt,value) printf(&quot;value = %&quot; #fmt &quot;\n&quot;, (value))


 * 1) include 

void main(void) {  float afl;

afl = 3.14f; PR(5.2f, afl); } The sample code outputs the following string:   value =  3.14 The # sign in front of the fmt variable allows the macro to be expanded using quotation marks. Note that the preprocessor concatenates consecutive pairs of double quotation marks so that the following string   &quot;value = %&quot;&quot;5.2f&quot;&quot;\n&quot; is translated into the following:   &quot;value = %5.2f\n&quot;

Additional query words: pound number

Keywords: kbinfo kblangc KB57949

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.