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

volatile modifier for bit?

I have a flag bit variable that is set by an interrupt routine. Then in my main loop the flag is checked like:

 adc0_flag = 0;
 while(1){
    if(adc0_flag == 1){
       adc0_flag = 0;
       process_data()
    }
 ...

 }
I tried declaring adc0_flag as:

volatile bit adc0_flag;

But this did not fix the problem that call to process_data() was optimized out [using no optimization--ie opt(0)]

Changing it to:
volatile unsigned char adc0_flag;

fixes the problem--but wastes memory. I have several such bit flags being modified by interrupts. Is there an alternative?

Is it true that volatile does nothing for bit variables or am I doing something wrong?

0