KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q43175: Bad Code Produced for specific source when optimizations used

Article: Q43175
Product(s): See article
Version(s): 1.00 1.01 2.00
Operating System(s): MS-DOS
Keyword(s): ENDUSER | buglist1.00 buglist1.01 buglist2.00 | mspl13_c
Last Modified: 18-MAY-1989

When compiling the source code below, the QuickC and QCL compilers
will produce incorrect code if any optimizations other than loop
optimization are enabled. If optimizations are disabled or only loop
optimization is used, the compilers will generate correct code.

Microsoft is researching this problem and will post new information as
it becomes available.

This program will demonstrate the problem when compiled with
optimizations enabled (/O):

#include <stdio.h>

void main( void )
{
    int a, b, c;

    a = 0;
    b = 2 - ( 63 * a );
    c = ( b % 31 );       /* c should be 2
                             (the remainder of 2/31) */

    if( b != c )
    {
         printf( "FAILED\n" );
         exit( 1 );
    }
    else
    {
         printf( "PASSED\n" );
         exit( 0 );
    }
}

                  Laguna Beach, CA 92651

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.

Copyright Microsoft Corporation 1986-2002.