Help me understand this statement:
static int ** volatile ptr
Please let me know how to analyze this pointer statement.
Help me understand this statement:
static int ** volatile ptr
Please let me know how to analyze this pointer statement.
static
means that this is static variable - only one copy in source code for local variables in function, not shared between modules for global.
int **ptr
means that ptr is pointer to a pointer to int
.
volatile
on the right side of *
means that the pointer itself is volatile and not the pointed value. volatile means that all accesses to this variable must be actual memory operations and most optimizations are not allowed.
To address the title text after inserting markers into it: 4(static int 3( * 2( * 1(volatile ptr))). Working inside out:
1: Variable that is free to change at run time for reasons the program may not be aware of. Popular causes are other threads, signals or other events, and pointers to "memory" that is really hardware controllers, etc. Stops compilers/optimizers from emitting code that can fail under such changes.
2: Volatile pointer to this memory. What is pointed to is not volatile.
3: pointer to pointer, or array of pointers. Think char **argv; Again, not volatile.
4: static: this depends on where in the declaration is found:
Interesting: const volatile indicates external influences can change the pointer but your software can not do so.