Improve "const correctness"
Brought to you by:
cminyard
Would you like to apply the advices from the article
"http://en.wikipedia.org/wiki/Const_correctness" to
your sources?
I suggest to add the key word "const" to the type
specifiers for parameters like the following.
- msg (function "ipmi_request"), addr (function
"ipmi_validate_addr")
http://cvs.sourceforge.net/viewcvs.py/openipmi/OpenIPMI/include/linux/ipmi.h?rev=1.6&view=markup
- heap (function "print")
http://cvs.sourceforge.net/viewcvs.py/openipmi/OpenIPMI/unix/heap.h?rev=1.1&view=markup
Commit: [03c5b6]
Commit: [04ba15]
Commit: [367a35]
Commit: [5d6460]
Commit: [67556d]
Commit: [99e597]
Commit: [afc9f6]
Commit: [b425e5]
Commit: [dba744]
Logged In: YES
user_id=236278
Ok, I've done this in the 2.0 releases. I'm not sure I'm
willing to backport this to 1.4, though, as the side-effects
may be too much.
Logged In: YES
user_id=572001
Are you going to check other files in the current release, too?
Logged In: YES
user_id=236278
I'm not sure what you mean. The changes are checked in to
the CVS head, but not into the 1.4 branch. There's a few
more things I want to deal with that are internal, and a
backwards compatibility problem with posix_vlog that I'm
going to fix a different way.
I'll look at doing just the changes you wanted to 1.4.
Logged In: YES
user_id=572001
I pointed just to two files for review.
Do you know more candidates for improvement already?
Logged In: YES
user_id=236278
Does the attached patch do what you suggest?
Logged In: YES
user_id=572001
Yes, this change list looks great. (Are the files "ipmi.h"
and "heap.h" excluded?)
I hope that new functions will be const-correctly designed
and developed from the beginning.
Logged In: YES
user_id=236278
Yes, I will keep this in mind for future updates. Thanks.
The 1.4.18 release has these changes.
ipmi.h is a kernel interface and heap.h is an internal
interface, so they are no as important. There's a few other
things, too, that need fixing. I'll do those over time,
probably.
Logged In: YES
user_id=572001
I suggest that this issue should be kept open until all
files will be fixed without exception.
Logged In: YES
user_id=572001
Do you notice any difference in the generated object code if
all proposed refactorings will be applied?
Logged In: YES
user_id=236278
I didn't look to see if anything changed. From this, I kind
of doubt it made much difference. The compiler can make
more optimizations with const types, but almost all the uses
of this are "Put the data into this container and pass it
in/on and don't use it any more". Not many new
optimizations that could be done there.
Logged In: YES
user_id=572001
Are you interested to know any measureable effects like
object file sizes if a const-correct design will become
available for your software?
Logged In: YES
user_id=236278
It would be interesting to know. If it made a difference,
it would be incentive to keep going :-).
Logged In: YES
user_id=572001
Would you like to join an other discussion?
http://groups.google.de/group/comp.lang.c/tree/browse_frm/thread/ed3e9f3bf137804e/171eed12e1b2c4c5
Logged In: YES
user_id=236278
I've gone over all the interface and I'm try to use const
whenever possible. Thanks for the heads-up.
Logged In: YES
user_id=572001
Thanks for this accepted correction.
Would you like to add a reference (case number) to this
issue to the change log or any comments?
This has been a while and I missed the last comment. I assume everything is ok, I'm not sure there's anything else I need to do.