Below is the code that points to the flash LED on the Pandaboard when starting the Barrelfish operating system. My question is why the LEDs do not blink if the keyword "volatile" is removed from the definitions gpio_oeand gpio_dataout.
static volatile uint32_t *gpio_oe = (uint32_t *)(GPIO_BASE + 0x0134);
static volatile uint32_t *gpio_dataout = (uint32_t *)(GPIO_BASE + 0x013C);
void led_flash
{
*gpio_oe &= (~(1 << 8));
while(true)
{
*gpio_dataout ^= (1 << 8);
time_delay();
}
}
I know that volatile needs to be used if the value of a variable can spontaneously change through a source outside the program. But I do not see such a case. What kind of optimization does the compiler do, which makes the entire while loop for the flashing LED pointless? And what is the logic of such optimization, i.e. a legitimate case where such an optimization would make sense?
gjain source
share