[snip]
IMO we should use const whenever is possible or am I wrong?
It is extremely important to be rigorously const-correct at interfaces.
It
is far less important in implementations.
But it might be a hint to the user or the programmer when inspecting the
source code that b and g will never change.
OK, who is this programmer who is inspecting the implementation? If he is
just a client of the code he is making a mistake. Any assumption he makes
about how the function is implemented is unwarranted and dangerous. He
should be looking at the interface and the documentation only. If he is
actually modifying the implementation a const here and there might be of
some help to him. Thus being const correct in the implementation has a minor
advantage.
I don't know if the compiler
does any optimization when we use const int b instead of int b.
This might result in some sort of minor efficiency improvement in some
cases. Again, being const correct in the implementation has a slight
advantage.
The importance of const correctness at the interface is much greater. It is
often critical to correct usage of the code by any client (not just a
re-implementor) and may prevent gross inefficiencies such as making backups
of large objects unneccesarily before making a call.
[snip]