M
Martin Dickopp
CBFalconer said:Martin said:I might have another use for the original pointer value, for example:
char *const p = malloc (len);
if (p != NULL)
{
/* image 150 lines of code here */
free (p);
}
This is a much different case from the incoming parameters example.
[...]
Remember, I am talking about function parameter values.
Yes. For consistency reasons, I treat parameters and local variables the
same, as far as `const' is concerned.
Should such a maintenance case occur, I suggest that:
1. The routine is too long.
I just /knew/ you were going to say that.
3. Now is the time to add the const to the parameter. If it
raises no flags on trial recompilation the original value hasn't
been touched. If it does, we can restore the original parameter
definition, add a const temporary to save the value at entry, and
use that later. In either case the const goes.
Actually, when I need to modify an object, but also need the original
value later, I prefer it the other way around: The parameter retains
its value und a temporary is modified.
Code diddling has been minimized.
I find maintenance easier if the const qualifier is there permanently,
instead of adding it, doing a trial recompilation, and then removing
it again.
Martin