Incorrect Global Value Initialization If You Use Precompiled Header (318139)



The information in this article applies to:

  • Microsoft Visual C++ .NET (2002)

This article was previously published under Q318139

SYMPTOMS

If you use a precompiled header (such as /Yu, /Yx, or /Yc), global values may not be initialized correctly.

RESOLUTION

A supported hotfix is now available from Microsoft, but it is only intended to correct the problem that is described in this article. Only apply it to systems that are experiencing this specific problem. This hotfix may receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next Microsoft Visual Studio .NET service pack that contains this hotfix.

To resolve this problem immediately, contact Microsoft Product Support Services to obtain the fix. For a complete list of Microsoft Product Support Services phone numbers and information about support costs, visit the following Microsoft Web site:NOTE: In special cases, charges that are ordinarily incurred for support calls may be canceled if a Microsoft Support Professional determines that a specific update will resolve your problem. The typical support costs will apply to additional support questions and issues that do not qualify for the specific update in question.

The English version of this fix should have the following file attributes or later:
   Date         Time    Version      Size       File name   Platform
   -----------------------------------------------------------------
   07-Mar-2002  15:57   13.00.9478   2,105,344  C1xx.dll    x86
   07-Mar-2002  15:57   13.00.9478   1,757,184  C2.dll      x86
				

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Create a new file named IncludeFile1.h, add the following code to IncludeFile1.h, and then save the file:
    const double gVal1 = 1234.567;
    const double gVal2 = gVal1;
    					
  2. Create a new file named IncludeFile2.h, add the following code to IncludeFile2.h, and then save the file:
    const double gVal3 = 10 * gVal2;
    					
  3. Create a new file named Stdafx.h, add the following code to Stdafx.h, and then save the file:
    #include "IncludeFile1.h"
    					
  4. Create a new file named Stdafx.cpp, add the following code to Stdafx.cpp, and then save the file:
    #include "Stdafx.h"
    					
  5. Use the following C++ compiler option on Stdafx.cpp:

    /Yc"stdafx.h"

  6. Create a new file named MyFile.cpp, add the following code to MyFile.cpp, and then save the file:
    #include "stdafx.h"
    #include "IncludeFile2.h"
    					
  7. Use the following C++ compiler option on MyFile.cpp:

    /Yu"stdafx.h"

    Notice that //gVal3 is incorrectly initialized for use in MyFile.cpp.

Modification Type:MinorLast Reviewed:10/11/2005
Keywords:kbHotfixServer kbQFE kbbug kbCompiler kbfix kbQFE KB318139 kbAudDeveloper