M
Morgan Cheng
Hi All,
I was taught that argument valuse is not supposed to be changed in
function body. Say, below code is not good.
void foo1(int x)
{
x ++;
printf("x+1 = %d\n", x);
}
It should be "refactor-ed" to be
void foo2(int x)
{
int y = x;
y ++;
printf("x + 1 = %d\n", y);
}
Recently, I found one guy posted code like foo1 in one C lang forum. I
pointed out that it is not good code standard. Surprisingly, seems all
people criticise me as dogmatism. It is claimed that changing arugment
value will not affect caller code and it saves stack size. I understand
their point, but I DO remember it is commmon that argument is not
suppsoed to be changed.
Now I am confused. Is there anybody can give some explaination why it is
a code rule that argument should not be changed?
Thanks & Regards
I was taught that argument valuse is not supposed to be changed in
function body. Say, below code is not good.
void foo1(int x)
{
x ++;
printf("x+1 = %d\n", x);
}
It should be "refactor-ed" to be
void foo2(int x)
{
int y = x;
y ++;
printf("x + 1 = %d\n", y);
}
Recently, I found one guy posted code like foo1 in one C lang forum. I
pointed out that it is not good code standard. Surprisingly, seems all
people criticise me as dogmatism. It is claimed that changing arugment
value will not affect caller code and it saves stack size. I understand
their point, but I DO remember it is commmon that argument is not
suppsoed to be changed.
Now I am confused. Is there anybody can give some explaination why it is
a code rule that argument should not be changed?
Thanks & Regards