Microsoft KB Archive/942122

= FIX: A symbol generates an inaccurate value when you use the CL.exe command together with the /O2 option to compile a C or C++ application =

Article ID: 942122

Article Last Modified on 11/20/2007

-

APPLIES TO


 * Microsoft Visual Studio 2005 Standard Edition
 * Microsoft Visual Studio 2005 Professional Edition
 * Microsoft Visual C++ 2005 Express Edition
 * Microsoft Visual Studio 2005 Express Edition

-





SYMPTOMS
When you use the CL.exe command together with the /O2 option to compile a C application or a C++ application, a symbol that is used both inside and outside a loop generates an inaccurate value.



CAUSE
This problem occurs because the symbol is incorrectly coded.



Hotfix information
A supported hotfix is now available from Microsoft. However, it is intended to correct only the problem that is described in this article. Apply it only 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 Visual Studio 2005 service pack that contains this hotfix.

To resolve this problem immediately, contact Microsoft Customer Support Services to obtain the hotfix. For a complete list of Microsoft Customer Support Services telephone numbers and information about support costs, visit the following Microsoft Web site:

http://support.microsoft.com/contactus/?ws=support

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 usual support costs will apply to additional support questions and issues that do not qualify for the specific update in question.

Prerequisites
You must have Microsoft Visual Studio 2005 Service Pack 1 installed to apply this hotfix.

Restart requirement
You do not have to restart the computer after you apply this hotfix.

Hotfix replacement information
This hotfix does not replace any other hotfixes.

File information
The English version of this hotfix has the file attributes (or later file attributes) that are listed in the following table. The dates and times for these files are listed in Coordinated Universal Time (UTC). When you view the file information, it is converted to local time. To find the difference between UTC and local time, use the Time Zone tab in the Date and Time item in Control Panel.

Visual Studio 2005, x64-based versions


STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the &quot;Applies to&quot; section.



MORE INFORMATION
For more information about how to enable a 64-bit Visual C++ toolset, visit the following Microsoft Developer Network (MSDN) Web site:

http://msdn2.microsoft.com/en-us/library/x4d2c09s.aspx

For more information about Visual C++ compiler options /O1 and /O2, visit the following MSDN Web site:

http://msdn2.microsoft.com/en-us/library/8f8h5cxt(VS.71).aspx

For more information about Visual C++ compiler options /Z7, /Zd, /Zi, and /ZI, visit the following MSDN Web site:

http://msdn2.microsoft.com/en-us/library/958x11bc(VS.71).aspx

For more information about software update terminology, click the following article number to view the article in the Microsoft Knowledge Base:

824684 Description of the standard terminology that is used to describe Microsoft software updates



Steps to reproduce the problem
  Use the following code to create a new .c file. Name the file gtest.c. struct str_1 {    char            *obj; struct str_1   *next; };
 * 1) define SIZE 3

struct str_2 {    int             size; struct str_2   *top; struct str_1   *free; };

int main {    int    i;     char   obj[100], *object; struct str_1 *s1, *top; struct str_2 s;    s.size=10; object=obj;

if (!(s1 = top = (struct str_1*) malloc (sizeof (struct str_1) * SIZE))) return -1;

for (i=0; inext = s1+1; s1->obj = object; }

// This should set the last next pointer to zero // not working with /O2 or /Ox optimization (s1-1)->next = (struct str_1 *) 0; // initializing it this way fixes it    // FIX: (top+SIZE-1)->next = (struct str_1 *) 0; s1 = top; for (i = 0; i < SIZE; i++, s1++) {        printf (&quot;>>> s1 (0x%p) next (0x%p) object (0x%p)\n&quot;,             s1, s1->next, s1->obj); }

s.free = top;

return 0; }  Run the following command at a command prompt:

CL.exe /O2 gtest.c

 Run the following command at a command prompt:

gtest.exe

 Run one of the following commands at a command prompt: <ul>  CL.exe /Zi gtest.c </li>  CL.exe /Za gtest.c </li></ul> </li> Run the following command at a command prompt:

gtest.exe

</li></ol>

When you compare the output from step 3 with the output from step 5, you see the problem that the &quot;Symptoms&quot; section describes.

Keywords: kbfix kbexpertiseadvanced kbpubtypekc kbqfe kbhotfixserver KB942122

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.