Q65107: Modulus Yields Incorrect Result When Used with /Ot
Article: Q65107
Product(s): See article
Version(s): 2.00 2.01
Operating System(s): MS-DOS
Keyword(s): ENDUSER | buglist2.00 buglist2.01 fixlist2.50 fixlist2.51 | mspl13_c
Last Modified: 31-AUG-1990
The following code using the modulus operator "%" yields incorrect
results under Microsoft QuickC version 2.00 when optimizations are set
to ON or FULL and release mode is selected.
The error also occurs when compiling using the qcl command if you use
the /O, /Ot, or /Ox optimizations.
To avoid the error, upgrade to QuickC version 2.50 or QuickC with
QuickAssembler version 2.51, or avoid the problem optimizations.
Neither version 5.10 or version 6.00 of the Microsoft C Compiler
demonstrate this error.
Sample Code
-----------
#include <stdio.h>
main ()
{
int x=26,
Number = 151-(3 * x),
Onesdigit = Number % 10;
printf("The one's digit is: %i\n",Onesdigit); // correct output is 3,
// buggy output is 0
}
Microsoft has confirmed this to be a problem with QuickC versions 2.00
and 2.01. This problem is corrected in versions 2.50 and 2.51.
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.