KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q43507: QuickC: Small and Medium Model Optimization Error

Article: Q43507
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: 2-MAY-1989

When compiling the source code below, the QuickC and QCL compilers
will produce incorrect code if any optimizations except loop
optimization are enabled.

If optimizations are disabled or only loop optimization is used, the
compilers will generate correct code. This problem only occurs in the
small and medium memory models (near data pointers).

The program shown below will demonstrate the problem when compiled
with optimizations enabled under the small or medium memory models.

When optimization is enabled,

   ps_ppr->ptr2

is converted to

   *(ps_ppr->ptr2)

The following code demonstrates this problem:

#include <stdio.h>

char *ppr1;
struct ps
        {
          char blank;
          char *ptr2;
        } p_s,*ps_ppr;

void main(void)
{
  char d = 'A';
  ppr1   = &d ;
  ps_ppr = &p_s;

  ps_ppr->ptr2 = ppr1;

  if( ppr1 != ps_ppr->ptr2)
    {
      printf("Optimization test..........Failed\n");
      printf("%Np does not equal %Np \n",ppr1,ps_ppr->ptr2);
      exit(1);
    }
  else
    {
      printf("Optimization test..........Passed\n");
      printf("%Np  = %Np \n",ppr1,ps_ppr->ptr2);
      exit(0);
    }
 }

Microsoft has confirmed this to be a problem in Versions 1.00, 1.01,
and 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.