PRB: Generating P-Code Disables Native Code Optimization

Last reviewed: July 17, 1997
Article ID: Q84478
7.00 | 1.00 1.50 MS-DOS | WINDOWS kbtool kbprb

The information in this article applies to:

  • The Microsoft C/C++ Compiler (CL.EXE) included with:

        - Microsoft C/C++ for MS-DOS, version 7.0
        - Microsoft Visual C++ for Windows, versions 1.0 and 1.5
    

SYMPTOMS

In Microsoft C/C++ version 7.0 and Visual C++ version 1.0, generating p- code with the /Oq compiler option or with the following pragma

   #pragma optimize( "q", on )

seems to disable other specified optimizations. Even using

   #pragma optimize( "q", off )

does not seem to restore optimization to the remaining native code.

CAUSE

This is a limitation of the p-code compiler. Any native code functions in a module compiled for p-code will get a /f level of optimization.

RESOLUTION

Break the module into two modules, one that uses native code and another that uses p-code.

MORE INFORMATION

The following sample code can be used to demonstrate the behavior. When compiled with /Olz, the code generated for the for loop places a 1 into j and returns. With /Oqlz, this optimization does not occur.

Sample Code

/* Compile options needed: /Oqlz /Fc
   Compile options needed: /Olz /Fc

   Compare the resulting listings generated by /Fc
*/

#pragma optimize( "q", off )

int main( )
{
   int i, j;

   for( i=0; i<10; i++ )    /* This loop should be optimized away. */
   {
      j = 1;
      j = 1;
      j = 1;
      j = 1;
      j = 1;
   }

   return j;
}


Additional reference words: 7.00 8.00 8.00c 1.00 1.50 pcode
KBCategory: kbtool kbprb
KBSubcategory: CLIss
Keywords : kb16bitonly


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: July 17, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.