E
Ed Morton
Anyone know why "const" isn't the default for function parameters? I almost
never see code where function parameters are modified intentionally (and when I
do, I usually think copying the value to a local variable would be clearer), but
I do occasionally see function parameters being incremented instead of
similair-sounding local variables or, in the case of pointers, instead of the
objects they point to.
e.g.:
void foo(int *x, int link)
{
int lnk = 0;
x++; /* Meant to increment *x */
link++; /* Meant to increment lnk */
....
}
I'm not trying to convince anyone to change the language, just curious about how
it ended up this way.
<OT> Has anyone come across a compiler or other tool that can report warnings
for non-const parameters being modified? </OT>
Ed.
never see code where function parameters are modified intentionally (and when I
do, I usually think copying the value to a local variable would be clearer), but
I do occasionally see function parameters being incremented instead of
similair-sounding local variables or, in the case of pointers, instead of the
objects they point to.
e.g.:
void foo(int *x, int link)
{
int lnk = 0;
x++; /* Meant to increment *x */
link++; /* Meant to increment lnk */
....
}
I'm not trying to convince anyone to change the language, just curious about how
it ended up this way.
<OT> Has anyone come across a compiler or other tool that can report warnings
for non-const parameters being modified? </OT>
Ed.