Re: Visual C++ 6.0 Compiler Problem with Optimizations Switched On

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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;
> > }
> >
> >
>
>
>
.



Relevant Pages

  • Problem in compiling a C code with MSVC++6.00
    ... When I save the file as a cpp file, it compiles and runs ... int p1; ... void checkfile; ... printf("cannot allocate memory for elements!"); ...
    (comp.lang.c)
  • Re: Errors in compilation of simple programme
    ... using namespace std; ... cin>> i; ... it compiles without a problem on Visual C++ ... int main ...
    (microsoft.public.vc.language)
  • Re: Prime Numbers
    ... /*This code finally compiles as a 'c' code ... One more question....if i don't free up the memory allocated at the end ... it would appear that we are best served by an array ... prime numbers can be represented by an unsigned long int. ...
    (comp.lang.c)
  • Re: small newbie question
    ... INT MyFunction; ... It compiles, ... because you used a big sledgehammer to force it ... Remove all casts from your code, unless you really know what you are ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: Errors in compilation of simple programme
    ... using namespace std; ... cin>> i; ... it compiles without a problem on Visual C++ ... int main ...
    (microsoft.public.vc.language)