Visual C++ 6.0 Compiler Problem with Optimizations Switched On !!



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


.



Relevant Pages

  • Visual C++ 6.0 Compiler Problem with Optimizations Switched On !!
    ... Recently I observed quite strange behavior of the MSVC++ 6.0 original ... if one compiles the source code attached below in the Debug ... int main ...
    (microsoft.public.vstudio.general)
  • Re: Modified version of the Gray parser generator
    ... where that code appeared in the source code. ... Of course the context is going to be different as the standalone ... the parser source code itself which makes me wonder if we're talking ... think of is that Gray compiles the action when the source code is read ...
    (comp.lang.forth)
  • Re: Source Code to Filter out WindowsMessenger POP-UPS
    ... I really have no idea where you can find decent firewall source code on ... Zone Alarm does NOT support 'server'. ... Very few ports are open, ... >sample code that compiles on Linux, ...
    (microsoft.public.inetserver.iis.security)
  • Re: 1987 Z80 C compiler 2500ad documentation
    ... compiles and runs with gcc 4, ... information about pref-defined preprocessor symbols. ... Here are the command line options: ... -S Create assembler output with source code as comments ...
    (comp.arch.embedded)
  • Re: Source Code to Filter out WindowsMessenger POP-UPS
    ... I second getting an application level software firewall. ... it's free source code doesn't make it any less dangerous. ... sample code that compiles on Linux, but how do you know that someone ... apply pass/fail rules to - provided the router isn't one ...
    (microsoft.public.inetserver.iis.security)