Suppose I have the following function:
void atomic_add(volatile unsigned * loc, unsigned incr );
And I have want to pass a variable to the first argument of this function.
unsigned a;
atomic_add(&a, 1);
volatile unsigned b;
atomic_add(&b, 1);
From volatile type qualifier, it should can be compiled.
Q1: Do both of them get the same results?
Q2: Does the pointer returned from mmap() can also be used as the first argument of this function?
Thanks!
First of all
locis not avolatile pointer. It is a pointer referencing avolatile objectYou can pass
volatileand notvolatileto this function, bout localy in the function your ocject will be treated asvolatile. It means that it will be read before every use, and saved to its storage after every change. It will not be "buffered" in he registers. Even if you*loc + *locthe referenced object will be read twice.To have a volatile pointer you need to declare it different way:
Q1 - yes
Q2 - yes