Re: Visual C++ 6.0 Compiler Problem with Optimizations Switched On !!
- From: "Aslan" <Aslanski2002@xxxxxxxxx>
- Date: Mon, 23 Jan 2006 12:05:09 +0200
"Bojan" <Bojan@xxxxxxxxxxxxxxxxxxxxxxxxx>, haber iletisinde þunlarý
yazdý:CABEF9EB-CA46-4A15-8178-5FAC3BEFC299@xxxxxxxxxxxxxxxx
> 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):
These things can happen! I tried to run your code yes the same thing on my
machine.
The problem is your ReturnInt1 function is so simple. Optimiser tries to
eliminate that code but fails.
After adding "inline" keyword, it was OK.
inline int ReturnInt1()
{
int Pitch=100;
return Pitch;
}
I also run into some strange optimisation problems couple of times.
>
> 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:
- References:
- Prev by Date: Visual C++ 6.0 Compiler Problem with Optimizations Switched On !!
- Next by Date: Re: Visual C++ 6.0 Compiler Problem with Optimizations Switched On !!
- Previous by thread: Visual C++ 6.0 Compiler Problem with Optimizations Switched On !!
- Next by thread: Re: Visual C++ 6.0 Compiler Problem with Optimizations Switched On
- Index(es):
Relevant Pages
|