KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q45349: A Problem with Division Always Returning 1

Article: Q45349
Product(s): See article
Version(s): 2.00
Operating System(s): MS-DOS
Keyword(s): ENDUSER | buglist2.00 | mspl13_c
Last Modified: 8-JUN-1989

QuickC has demonstrated difficulty performing division under certain
circumstances. When time optimization (/Ot or /Ox) is enabled,
the program below outputs the following:

   quotient = 1

The correct value is 5. No matter what the division operands are, the
result is always 1 in this program. This behavior does not occur with
longs or floats -- only with ints. The program that demonstrates this
behavior is the following:

   #include <stdio.h>

   struct X
   { int i; } x = { 3 };

   void foo (struct X *);

   void main (void)
   {
     int denom, quotient;

     foo (&x);
     denom    = x.i;
     quotient = 15/denom;

     printf ("quotient = %d", quotient);
   }

   void foo (struct X *adr)
   {}

To work around this problem with the program listed, disable time
optimization. In the integrated environment, select
Options.Make.Compiler Flags.Off. From the QCL command line, do not
specify /Ot (or /Ox which implies /Ot).

This problem can also be observed with the "C For Yourself" program
GRAPHIC.C. The output of this program compresses when it is compiled
with time optimization enabled.

Microsoft has confirmed this to be a problem with QuickC Version 2.00.
We are researching this problem and will post new information as it
becomes available.

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.