Re: Visual C++ 6.0 Compiler Problem with Optimizations Switched On
- From: "Bojan" <Bojan@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 23 Jan 2006 03:50:02 -0800
Hi!
Thank you for your answer!
The function you mentioned was originally not so simple. I simplified it
intentionaly in order to focus the problem. I don't think that the function
is to simple. If you put in the for loop the statement "array[j]=60*counter;"
the results appears to be correct and expected. What does the keyword
"inline" really mean?
Best regards
Bojan
"Aslan" wrote:
>
> "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:
- Re: Visual C++ 6.0 Compiler Problem with Optimizations Switched On
- From: Aslan
- Re: Visual C++ 6.0 Compiler Problem with Optimizations Switched On
- From: Bruno van Dooren
- Re: Visual C++ 6.0 Compiler Problem with Optimizations Switched On
- References:
- Prev by Date: Re: 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: Re: 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
|