I understand that the declaration
int *volatile ptr;
means that the pointer itself is volatile
int a=10;
int *volatile ptr=&a;
Now both ptr
and a
are being updated. Will it cause any potential problems like old value of a
being returned when accessing ptr
?
To clarify the use case of volatile pointer in my scenario:
- To communicate from interrupt context to task context I am passing addresses to circular queue (which is array of pointers) which will be accessed from task context.
- The pointers in this queue are declared volatile.
- At index x in queue ,pointer y is present which points to variable a.
- Now if I write new pointer to queue (example pointer z which points to variable b) at index x in interrupt context.
- When I read index x in task context, since queue is declared as volatile, the pointers will not be optimised.
My doubt is since what the pointer is pointing to is not volatile is there a chance that compiler has optimized for index x and on deferencing pointer at index x it will point to variable a instead of variable b