How to declare a pointer to function in C, in order that the pointer itself is volatile.
static void volatile (* f_pointer)(void*);
static void (volatile * f_pointer)(void*);
static void (* volatile f_pointer)(void*);
Why I asking this? I read at http://wiki.answers.com/Q/Volatile_example_code_sample_coding_of_volatile_pointer about volatile pointers.
There are sometimes problems with volatile pointers and pointer-to volatile:
Now, it turns out that pointers to volatile variables are very common. Both of these declarations declare foo to be a pointer to a volatile integer:
volatile int * foo;
int volatile * foo;
Volatile pointers to non-volatile variables are very rare (I think I've used them once), but I'd better go ahead and give you the syntax:
int * volatile foo;
So, I want to get a volatile pointer to function not a pointer to "volatile" function.
Thanks
volatilereally means?{ barrier, pointer read, calling function }). I use a system with a lot of registers available, so compiler may cache a lot of variables. Am I right?volatileshould be unnecessary.a=1; pthread_barrier(); b=a;Is the pthread_barrier a wrong written one? Compiler knows nothing about insides of this function. Can the compiler cache the value ofaaround this function call (in its point of view it is usual func. call)? Compiler can cache any non-volatile variable.pthread_barrier_wait()must act as a compiler barrier (which prevents values from being cached across it). In practice, specific compiler support is unnecessary, becausepthread_barrier_wait()is an external function, so the compiler must assume that it could modify any global variable or any variable whose address has been taken (that is, from the compiler's point of view it ispthread_barrier_wait()that might have modifieda, rather than another thread).