Re: volilate int
**broken link removed**
then read this
volatile is a keyword, it tells compiler that this variable may change its value due to something not known to compiler.
e.g. considor following segment
unsigned char ch;
unsigned char my_func(void)
{
ch = 0xFF;
....... //some code lines
....... //these lines donot change value of ch directly or indirectly
.......
.......
if(ch == 0)
{
return(0);
}
else
{
return(1);
}
}//end of my_func
in the above segment ch is global variable initialised to 0xFF.
hence while compiling if..else compiler knows value of ch is 0xFF, hence it will omit the if..else statement & returns 1 irrespective of value of ch.
it is possible that some ISR is making ch = 0, which compiler may fail to visualise.
On the other hand if we declare it as volatile compiler will compile if..else though it knows that ch is initialised to 0xFF.