BUG: CodeView Executes Entire Single Statement Loop

Last reviewed: May 1, 1996
Article ID: Q85512
The information in this article applies to:
  • Microsoft CodeView for MS-DOS, versions 2.2, 3.0, 3.11, 3.14, 4.0, 4.01, 4.05, and 4.1
  • Microsoft CodeView for OS/2, versions 2.2, 3.0, 3.11, 3.12, and 3.5
  • Microsoft CodeView for Windows, versions 3.0, 3.05, 3.06, 3.07, 4.0, 4.01, and 4.1
  • Microsoft CodeView for Win32s, version 4.25

SYMPTOMS

Under certain circumstances CodeView will execute an entire for, while, or do-while loop containing a single line of source code. CodeView may appear to hang if the loop does many iterations, but that is not the case.

RESOLUTION

A detailed resolution follows. In the case of while and for loops, use braces in the loop body and do not have the closing brace on the same line as the single-line statement. In the case of do-while loops, do not have the while on the same line as the single-line statement.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

The following forms of for, while, and do-while loops execute completely while trying to single step under CodeView:

   for( initialize ; test ; action )
      statement1, statement2, ..., statementn;

   for( initialize ; test ; action )
   {  statement1, statement2, ..., statementn; }

   for( initialize ; test ; action ) {
      statement1, statement2, ..., statementn; }

   for( initialize ; test ; action )
   {
      statement1, statement2, ..., statementn; }

   while( condition )
      statement1, statement2, ..., statementn;

   while( condition )
   {  statement1, statement2, ..., statementn; }

   while( condition ) {
      statement1, statement2, ..., statementn; }

   while( condition )
   {
      statement1, statement2, ..., statementn; }

   do statement1, statement2, ..., statementn; while( condition );

   do
      statement1, statement2, ..., statementn; while( condition );

   do { statement1, statement2, ..., statementn; } while( condition );

   do
   {  statement1, statement2, ..., statementn; } while( condition );

The following forms of for, while, and do-while loops execute as expected when single stepping under CodeView:

   for( initialize ; test ; action )
   {
      statement1, statement2, ..., statementn;
   }

   for( initialize ; test ; action ) {
      statement1, statement2, ..., statementn;
   }

   while( condition ) {
      statement1, statement2, ..., statementn;
   }

   while( condition )
   {
      statement1, statement2, ..., statementn;
   }

   do statement1, statement2, ..., statementn;
   while( condition );

   do
      statement1, statement2, ..., statementn;
   while( condition );

   do { statement1, statement2, ..., statementn; }
   while( condition );

   do
   {   statement1, statement2, ..., statementn; }
   while( condition );

The for, while, and do-while loops also execute correctly if multiple statement lines are broken up into separate lines. The following source code appears to hang when tracing into or stepping over with CodeView. The following code does not demonstrate every case, but the behavior is the same for all of the cases above.

Sample Code

/* Compile options needed: /Zi /Od
*/

#define SIZE 500

int array[SIZE];

int main(void)
{
   int index = 0, flag = 0;

   for( index = 0; index < SIZE ; index++)
      array[index] = index;  /* CodeView appears to hang
                                here. Wait and the loop
                                will execute completely.
                             */
   index = 0;

   while( index < SIZE )
   array[index] = index, flag = index++; /* CodeView appears to hang
                                            here. Wait and the loop
                                            will execute completely.
                                         */
   return ( 1 );
}


Additional reference words: 3.00 3.50 4.00 4.10
KBCategory: kbtool kbcode kbbuglist
KBSubcategory: CvwIss


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: May 1, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.