The stuff to the left of the * is what the pointer points at.
The stuff to the right of the * is the qualifiers on the pointer itself.
So... volatile char* volatile * const ptr
is... a pointer that can't be changed, that points to a volatile pointer that points to volatile chars
Woo!
Never thought of it that way... that's a pretty nifty mnemonic!
ReplyDeleteIf you get into the habit of writing your qualifiers on the right (which I have to admit I usually don't do myself), then definitions like this can be easily read simply by tokenising then scanning right to left. So, your original type:
ReplyDelete"volatile char* volatile * const"
.. can be rewritten as the functionally-identical:
"char volatile * volatile * const"
Then, when this is read from right to left, it is quite obviously a constant pointer to a volatile pointer to a volatile character. Et voila! ;)
Its long when I stopped coding in c So almost forgot the concepts of pointers and how they are used and syntax.But your post helped me to recollect all the facts.Pointers are always a confusing until you have some application with proper use of pointers
ReplyDelete