#pragma optimize( "", off|on ) Does Not Affect P-Code

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

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
    

SUMMARY

Microsoft C/C++ compilers do not turn p-code optimizations on or off by using the #pragma optimize preprocessor directive if the string passed into the pragma is an empty string. The pragma optimize does work as expected if the string contains a "q".

MORE INFORMATION

This is expected behavior. The /Oq compiler option switch actually specifies more than an optimization--it is a compiler mode change. For this reason it must be explicitly listed in the #pragma optimize directive for it to be affected. The following is an example of turning off all optimizations and restoring default optimizations, including p-code:

   #pragma optimize("", off)
   #pragma optimize("q", off)

   #pragma optimize("", on)
   #pragma optimize("q", on)

In the following sample code, the main function is compiled with p-code, and the function HamAndEggs is not. The #pragma optimize statements with empty strings have no effect. This can be verified by examining a mixed source-assembly listing.

Note that the optimize with p-code option (/Oq) must be specified on the command line in order to use the optimize pragma with "q".

Sample Code

/* Compile options needed: /Oq /Fc
*/

#include <stdio.h>

void HamAndEggs( void );

// The following directive should turn off p-code generation.
#pragma optimize( "", off )

void main( )
{
   printf( "This function is using p-code\n" );
   HamAndEggs( );
}

// The following line turns p-code generation off.
#pragma optimize ( "q", off )

// The following line should turn p-code generation on.
#pragma optimize( "", on )

void HamAndEggs( )
{
    printf( "This function is not using p-code\n" );
}


Additional reference words: kbinf 7.00 1.00 1.50 8.00 8.00c pcode
KBCategory: kbtool
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.