Re: Should function argument be changed in function body?
- From: CBFalconer <cbfalconer@xxxxxxxxx>
- Date: Tue, 19 Jul 2005 06:55:17 GMT
pete wrote:
> CBFalconer wrote:
>>
.... snip ...
>>
>> The only reason not to modify arguments is that the initial value
>> is required later.
>
> I don't think that's a good reason.
> If the specifcation were to suddenly change from the code example
>
> void foo1(int x)
> {
> x ++;
> printf("x+1 = %d\n", x);
> }
>
> to
> int foo1(int x);
> with the return value being the initial value of x,
> I would do it this way:
>
> int foo1(int x)
> {
> const int y = x;
>
> x ++;
> printf("x+1 = %d\n", x);
> return y;
> }
I wouldn't. What has ++ got to do with anything? I would write:
int foo1(int x) {
printf("x+1 = %d\n", x+1);
return x;
}
easily read by non C programmers and which is also easily modified
to return void. I don't believe in returning the value of entry
parameters anyhow, because that leads to such ugly foulups as:
printf("%s %s\n", b, strcat(b, a));
You will never have this foulup using strlcat.
--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
.
- Follow-Ups:
- Re: Should function argument be changed in function body?
- From: Old Wolf
- Re: Should function argument be changed in function body?
- References:
- Should function argument be changed in function body?
- From: Morgan Cheng
- Re: Should function argument be changed in function body?
- From: CBFalconer
- Re: Should function argument be changed in function body?
- From: pete
- Should function argument be changed in function body?
- Prev by Date: Re: meaning of the error ?
- Next by Date: Re: meaning of the error ?
- Previous by thread: Re: Should function argument be changed in function body?
- Next by thread: Re: Should function argument be changed in function body?
- Index(es):
Relevant Pages
|