
Forther my previous mail. It was already late and I misread something when reading http://www.possibility.com/Cpp/const.html Something like: gchar const * const get_help (void) { return _help; }
would also be overkill is not it, and it would also break compilation
2010/9/19 Kris De Gussem <kris.degussem@...400...>:
A few months ago we had a thread about static code analysis with coverity. However, I have not heard anything from it anymore. So I just installed myself another static code analysis software packet, cppcheck. I played with it a bit and stumbled upon several notifications of functions that could be const. See e.g. the extract of the log:
[E:\Inkscapecode\inkscape\src\extension\extension.h:122]: (style) The function 'Extension::get_help' can be const [E:\Inkscapecode\inkscape\src\extension\param/parameter.h:111]: (style) The function 'Parameter::name' can be const [E:\Inkscapecode\inkscape\src\extension\param/parameter.h:116]: (style) The function 'Parameter::get_tooltip' can be const [E:\Inkscapecode\inkscape\src\extension\param/parameter.h:119]: (style) The function 'Parameter::get_gui_hidden' can be const [E:\Inkscapecode\inkscape\src\extension\dbus\dbus-init.cpp:87]: (style) Unused variable: obj [E:\Inkscapecode\inkscape\src\extension\dbus\dbus-init.cpp:104]: (style) Variable 'error' is assigned a value that is never used
So the first item lists line 112 of extension.h: gchar const * get_help (void) { return _help; }
which should return the pointer to a string in a private variable.
However what should be const? The pointer, the string to which the pointer points to or both? Aparently the pointer should be const, no? (e.g. to ensure that the string can not be deleted in some buggy code that calls get_help, leaving the pointer_help in the class pointing to some odd data chunk?)
This would result in: gchar * const get_help (void) { return _help; }
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
Regards Kris