Hi,
for a paper I'm looking for an real-life C function which uses volatile variables. That in itself is not hard to find, but I am looking for a function in which the value of the volatile variable must change during the course of the execution of the function, for a particular branch of the function to be reached. Something like this:
typedef struct {
unsigned :6;
unsigned FLAG1 :1;
unsigned FLAG2 :1;
} __attribute__ ((packed)) REGISTER;
volatile REGISTER * io_ = 0x1234;
int write_to_io()
{
while (io_->FLAG1) {};
//io_->FLAG1 is now 0
io_->FLAG2 = 1;
sleep(10);
if (io->FLAG1)
return 1; //io->FLAG1 has changed from 0 to 1
else
return 0; //io->FLAG1 has not changed
}
It would be sufficient if different bits of the structure changed during the execution of the function, but my main criterion is that for a certain branch to be reached, the value of a volatile variable changes during the execution of the function.
I'd be very grateful for any real-life examples. I haven't been able to find many examples using volatile on the web.