I’m reading through a C code base, and I found a snippet that looks something like this:
void foo(int bar) {
const int _bar = bar;
...
}
The author then uses _bar throughout the rest of the code. Why is this done? Is it an optimization, or is there some other reason?
Presumably the author does this to avoid accidental assignment.
If the param is unchanged from the function input, the author could put the const in the param signature, as in
void foo (int const bar) { ... }.