FIX: C Run-time Include Files Missing #pragma Pack Directives

Last reviewed: September 18, 1997
Article ID: Q122275
1.00 2.00 WINDOWS NT kbprg kbfixlist

The information in this article applies to:

  • The C Run-time (CRT), included with:

        - Microsoft Visual C++, 32-bit Edition, version 2.0
        - Microsoft Visual C++, 32-bit Edition, version 1.0
    

SYMPTOMS

The include (.H) files shipped with Visual C++ do not use the #pragma pack preprocessor directive around declarations of structures used by C run-time functions. You may run into problems using C run-time functions in your program if:

  • You are compiling files with the /Zp compiler option and using a value other than 8 as the argument.

    -or-

  • You are using #pragma pack in your source files.

CAUSE

Problems occur because most C run-time functions expect the structures they work on to be built with the default compiler structure packing. The structure packing they expect would be specified with one of these compiler options: /Zp8, /Zp, or no /Zp.

RESOLUTION

If you are changing the default structure packing when building your application, add #pragma pack directives around the #includes of the C run-time include files to specify 8 as the packing alignment. This is illustrated in the sample code shown in the More Information section.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This problem was fixed in Microsoft Visual C++, version 4.0.

MORE INFORMATION

There are other potential problems with changing the default structure packing. For additional information, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q117388
   TITLE     : PRB: Structure Packing Causes Some Win32 Programs to Fail

REFERENCES

Visual C++ Build Tools User's Guide, Chapter 2, Using the 32-Bit CL. A description of the /Zp compiler option.

Visual C++ Preprocessor Reference, Chapter 2, Pragma Directives. A description of #pragma pack.

Sample Code

/* Compile options needed: none
*/

#pragma pack( push, 8 )
#include <stdio.h>
#pragma pack( pop )

void main( void )
{
    FILE *fp;

    fp = fopen( "c:\\autoexec.bat", "r" );
}


Additional reference words: 1.00 2.00 runtime run time error errors errno
KBCategory: kbprg kbfixlist kbbuglist
KBSubcategory: CRTIss
Keywords : CRTIss kbbuglist kbfixlist kbprg
Version : 1.00 2.00
Platform : NT WINDOWS
Solution Type : kbfix


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