Spent most of the day hunting down a bad "*". It was a simple mistake, and one easy to overlook. It goes something like this.
The above had been moved so it was initialized inside of an init function, rather then the declaration. The code changed to this:
Buried in hundreds of other lines, this mistake is easy to overlook. What happened is simple: a copy and paste copied too much. Instead of setting the location of the pointer, the uninitialized pointer was dereferenced and whatever it pointed to was set to some constant. This is not what was intended.
Now here is something to think about. Some people do like to add the asterisk directly in front of the declaration. Maybe do it because of this situation:
This is legit. However, I've always been of the school "one statement per line". In this case, I would break the declaration into two lines. And, I always place a space between the asterisk and the variable name.
I still use no space when dereferencing with an asterisk.
There are a few other operations I do this for as well:
The mistake in the above scenario is a little harder to make when declaring variables like this. The asterisk in the decoration (meaning pointer) has a different meaning then the asterisk in variable usage (meaning dereference). It is unlikely someone would have copied too much if there was a space after the asterisk in the declaration.
Now some crazy stuff and why I use the spacing and naming methods I do:
Read it from right to left and it makes sence:
"pointer_A is a volatile pointer to a constant pointer to an integer."
"pointer_B is a volatile pointer to a constant pointer to a constant integer"
"pointer_C is a pointer to a pointer to a constant integer".
See how the spacing helps to distinguish the multiplication from the dereferencing?
To finish up, let's look at some more C code examples of what can be done, but probably shouldn't be used.