gu**********@yahoo.com (gc) wrote in message news:<79**************************@posting.google. com>...
I came across certain code with lot of declarations like:
int foo(const double bar,const int m);
I do not see any point in making a non pointer parameter a const, or
am I missing something?
Why not? I would say that it is definitely to the point if you can
say to the compiler that you will *not* be changing bar or m inside
the function foo. Ok, this value will not propagate to the caller,
which is why making a pointer, a constant is a good idea. However if
you are sure that your function should not manipulate these values
inside the function, its a good idea to give yourself a compile time
escape route.
For instance :
<code excerpt>
void foo(int bar[],const int noElements) {
unsigned int i;
for(i=0;i<noElements;i++) }
/* blah blah... whatever you want to do with bar[i] */
/* What would happen if you inadvertently put a noElements--
around here */
}
}
It is a good idea to make a non pointer parameter const for this
reason.
Regards,
Anupam