This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

a global variable is altered by non related functions

Hi,

There is a strange behavior in my project. I declare a global variable SwitchToBtFlag in project.h

#ifdef _project_c_
	#define AUTOEXT
#else
	#define AUTOEXT extern
#endif,

AUTOEXT volatile bit SwitchToBtFlag;

#undef AUTOEXT
This variable is set/clear by fun_a() and checked and cleared by fun_b(). Both functions are in different file.
void fun_a( void )
{
	…
	if( condition )
		SwitchToBtFlag = 1;
	else
		SwitchToBtFlag = 0;
	…
}

void fun_b( void )
{
	…
	if( SwitchToBtFlag )
	{
		SwitchToBtFlag = 0;
		…
	}
}
Somehow (I can not figure out) SwitchToBtFlag will be altered by some other functions that is totally not accessing (or related) to the variable. What possible reasons can cause this problem. Thanks for answering my question.

chao.

0