I know that this is allowed in C, but I am used not to update the value of a variable passed by value.
In my "coding style", a parameter passed by value is not changed. I mean that I prefer this:
void func(int var)
{
int locVar = var;
if(something)
{
locVar = locVar/2;
}
// [some stuff using locVar]
}
over this:
void func(int var)
{
if(something)
{
var = var/2;
}
// [some stuff using var]
}
I assume that the compiler will not produce different assembly if the register optimizations are enabled, but still, is there any good reason to prefer one of the two code snippets?
Note: var is not volatile.
