Microsoft KB Archive/62097

= INFO: Line Continuation Evaluated Before Inline Comment =

Article ID: 62097

Article Last Modified on 7/5/2005

-

APPLIES TO


 * Microsoft C Professional Development System 6.0a
 * Microsoft C Professional Development System 6.0a
 * Microsoft Visual C++ 1.0 Professional Edition
 * Microsoft Visual C++ 1.5 Professional Edition
 * Microsoft Visual C++ 1.0 Professional Edition
 * Microsoft Visual C++ 2.0 Professional Edition
 * Microsoft Visual C++ 4.0 Standard Edition
 * Microsoft Visual C++ 5.0 Standard Edition
 * Microsoft Visual C++ 6.0 Service Pack 5

-



This article was previously published under Q62097





SUMMARY
To maintain ANSI compliance, the above C versions evaluate line continuation characters &quot;\&quot; before inline comment tokens &quot;//&quot;. This is a change from C version 5.1 behavior, which ignores line continuation characters within inline comments. This order of evaluation may results in the following error in the sample below:

error C2065: 'INT2' : undeclared identifier



MORE INFORMATION
Section 2.1.1.2 of the ANSI Draft proposal (dated December 7, 1988) states the order in which source code translation is to take place. The second and third steps are paraphrased below.

2. Each instance of a new-line character and an immediately preceding backslash character is deleted, splicing physical source lines to form logical source lines. ...

3. The source file is decomposed into preprocessing tokens and sequences of white-space characters... Each comment is replaced by one space character.

As this indicates, the line concatenation should be performed before any and all evaluation of preprocessing tokens and comments. The change in interpretation can cause problems with programs that depend on the C 5.1 interpretation. The problem usually manifests itself in sections of code being ignored. This can be seen in the following program, which behaves differently under the different compilers.

Sample Code

 * 1) include 


 * 1) define INT1 1         //    Inline comment    \
 * 2) define INT2 2   //  This line is ignored  \

void main(void) {  printf(&quot;%d %d \n&quot;,INT1,INT2); }

Additional query words: 8.00 8.00c 9.00

Keywords: kbinfo kbcode kbcompiler KB62097

-

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

© Microsoft Corporation. All rights reserved.