
On Sep 19, 2010, at 1:26 PM, Kris De Gussem wrote:
Or is there something that I am missing? BTW: this is just an example, the same reasoning is valid for the listings in parameter.h
Sorry for the bit of distraction on that last response. I did spot a key thing you were missing in most of these warnings.
Start by thinking Object-Oriented. Say we have an "Extension" object. Often we have one of these
Extension const *ptr = getSomeComplexThing();
So we have a pointer to an object that we're not allowed to change. A const method is a method that won't change an object it is called on. To mark a method const, simple place "const" at the end of the method declaration, and before any body if present.
gchar const *get_help() const;
That takes care of the "how". Now to get on to the "why" part in play here. One thing I found through most of those methods is that they all start with "get". That is a clue. The methods are accessors (or "gettors"). That is, they give a way to read a property of an object. Usually accessors are const so that one can read safely from any object.
So in general what that tool is saying matches up with our concept of an OO accessor. Those methods that are accessors should be const methods. (in a similar vein input parameters that are pointers or references should also be const).