Tech Support > Microsoft Windows > Development Resources > Strange problem of VC 6.0 debugger
Strange problem of VC 6.0 debugger
Posted by Vladimir Beker on August 5th, 2004


Hi, I have very strange problem with VC++ (6.0).
Consider the following program:

#include <stdio.h>

int MAIN = 0;

int main()
{
if (MAIN==0)
{
printf("ok");
}
else
{
printf("bug");
}

getchar();
return 0;
}

getchar() is called only to wait when running from VC.
If the program is started from command line, it prints "ok" - as expected,
since MAIN variable is initialized to zero.
However, even if it is started in debugger (without any breakpoints), it
prints "bug". Still, if you put breakpoint on 'printf' call you see that the
variable is 0.
I should note that if you rename the variable, the problem disappear.
Did anyone see something like this?
Thanks
Vladimir


Posted by Victor Bazarov on August 5th, 2004


Vladimir Beker wrote:
Strange problem indeed.

I didn't and I still don't. Just built your code in VC++ 6.0 and ran it
under the debugger. It printed "ok" and waited for my input. All seems
fine here.

It could be that inclusion of your 'stdio.h' somehow defines 'MAIN' as
a macro that affects the code. It could also be that your project itself
defines 'MAIN' in a similar fashion. I cannot imagine what it has to be
defined as to give such effect, but who cares?

Preprocess your code and look at what source is actually given to the
compiler. See what 'MAIN' is transformed into.

BTW, is that a C++ program or a C program?

Victor