180. Static Memory

Question.9

A static variable is shared between an ISR and the main loop:

static volatile bool flag = false;

void UART_IRQHandler() {
   flag = true;  // Set in ISR
}

int main() {
   while (!flag) {}  // Wait in main loop
   process_data();
}

Why is volatile necessary?

Need Help? Refer to the Quick Guide below

Select Answer