Page 1 of 1

problem with getch loop

Posted: Sun Sep 23, 2007 1:49 pm
by kubeos
Here's my code:

Code: Select all

int getch()
{
	char timewaster[5];
	result=0;
	do{
		result=asckey;
		if(result!=0)
		{
			asckey=0;
			return result;
		}
		//memset(timewaster,0,5);
	}while(1);
}
Now, it works fine when the memset line is UNCOMMENTED.. but when I do comment it out.. it doesn't work? Does anyone who is good with C have an idea?

PS. asckey is in my kb isr, which seems to be fine.. if you want me to post that too.. i will. result and asckey are both global vars.

Thanks for any replies.

Posted: Sun Sep 23, 2007 2:43 pm
by frank
Try making asckey and result volatile.

ie

Code: Select all

volatile int asckey;
etc.

yes

Posted: Sun Sep 23, 2007 3:11 pm
by kubeos
Wow, that fixed it... thanks!!

I'll have to see if there's a parm that I can pass to gcc to stop optimizations.

Posted: Sun Sep 23, 2007 3:32 pm
by frank
Try

Code: Select all

-O0