Hello folks,
The code (below) exhibits the following (strange) behavior:
WHEN AGE IS DECLARED AS A LOCAL VARIABLE IN MAIN:
1. program does not work as expected
2. "age" is not available in the debug watch window
WHEN AGE IS DECLARED AS A GLOBAL VARIABLE (JUST ABOVE MAIN):
3. program works as expected
4. "age" is available in the debug watch window
(Could this be because I am using Windows Vista?)
Any help is greatly appreciated.
Best Regards,
Chris
#include<stdio.h>
int main(void)
{
int age;
age = 18;
switch(age)
{
case 16 :
case 17 :
printf("Old enough to drive\n");
break;
case 18 :
case 19 :
case 20 :
printf("Old enough to vote\n");
break;
case 21 :
printf("Old enough to drink\n");
break;
}
return(0);
}
Take optimization off (none) and look it in debugger again.
Quote from: chassan on March 30, 2010, 05:13:52 AM
Hello folks,
The code (below) exhibits the following (strange) behavior:
WHEN AGE IS DECLARED AS A LOCAL VARIABLE IN MAIN:
1. program does not work as expected
Well, can you be a bit more specific as to what you expect. It seems you have at least a major logic error in your program, not sure if that is causing to thwart your expectations... ;)
Ralf
Hi,
I had a similar problem with static variables.
Look at http://forum.pellesc.de/index.php?topic=3014.0 (http://forum.pellesc.de/index.php?topic=3014.0)
It was OK with PellesC 5.
Henrin
Hi Folks,
Thanks for all the input. It worked when I selelcted "none" for the compiler optimization level.
Best Regards,
Chris