Visual C++ 6.0 Compiler Problem with Optimizations Switched On !!
- From: "Bojan" <Bojan@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 23 Jan 2006 01:09:03 -0800
Dear all!
Recently I observed quite strange behavior of the MSVC++ 6.0 original
compiler. Namely, if one compiles the source code attached below in the Debug
mode or in the Release mode without optimizations, it works like predicted.
See the standard output of the command prompt (compare the values with the
code below):
D:\Bojan\Research\IHNE\DEBUG1\Release>ihne.exe
The value of 'temp' should be 100: 100
The value of 'Index' should be 100: 100
This value should be 100, but we get the following: 100
This value should be 100, but we get the following: 112
However, if one compiles the same source code in Release mode with “Maximize
Speed” OR with “Minimize Size”, then an unpredicted behavior can be achieved.
After invocation of the program in the command prompt the following standard
output is produced.
D:\Bojan\Research\IHNE\DEBUG1\Release>ihne.exe
The value of 'temp' should be 100: 100
The value of 'Index' should be 100: 100
This value should be 100, but we get the following: 4223344
This value should be 100, but we get the following: 4223356
Please, pay attention on the strange values of the variable “counter”!!
What could be a problem here? Is something wrong with the code or it is the
optimization problem of the Microsoft Visual Studio (Visual C++) 6.0?
Best regards
Bojan
University of Maribor
Slovenia
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <fstream.h>
int ReturnInt1()
{
int Pitch=100;
return Pitch;
}
int main()
{
int j;
int index;
int counter;
int array[2000];
int temp=0;
// 1. The problem is in this case:
temp=ReturnInt1();
printf("\nThe value of 'temp' should be 100: %d\n",temp);
fflush(stdout);
index=temp;
printf("The value of 'Index' should be 100: %d\n",index);
fflush(stdout);
counter=0;
for (j=0;j<index;j++)
{
array[j]=60;
counter++;
}
printf("\nThis value should be 100, but we get the following: %d
\n",counter);
fflush(stdout);
printf("This value should be 100, but we get the following: %d
\n",counter+12);
fflush(stdout);
return 0;
}
.
- Follow-Ups:
- Re: Visual C++ 6.0 Compiler Problem with Optimizations Switched On !!
- From: Frédéric Fuzier
- Re: Visual C++ 6.0 Compiler Problem with Optimizations Switched On !!
- From: Aslan
- Re: Visual C++ 6.0 Compiler Problem with Optimizations Switched On !!
- Prev by Date: Re: Automatic lvalue in functions
- Next by Date: Re: Visual C++ 6.0 Compiler Problem with Optimizations Switched On !!
- Previous by thread: build error C3767, cli+mfc
- Next by thread: Re: Visual C++ 6.0 Compiler Problem with Optimizations Switched On !!
- Index(es):
Relevant Pages
|