Re: Re-use the argument?
Malcolm McLean wrote, On 09/06/08 20:57:
Often if you pick the names appropriately the above rules allows
modifying them.
int send(unsigned char *txbuf, size_t bytes_to_send)
{
int ret=0;
while (bytes_to_send) {
ret = low_level_send( txbuf,bytes_to_ send);
if (ret 0) {
bytes_to_send -= ret;
txbuf += ret;
}
}
return ret;
}
The above is a simplification of a real and very important function in
one of my companies major applications. The real function has error
checking and low_level_send is actually a system-specific function which
is not guaranteed to send all of the data and return the amount of data
it sent. There are other ways it could be implemented, but this is
approximately how I did it.
--
Flash Gordon
Malcolm McLean wrote, On 09/06/08 20:57:
"Richard Tobin" <richard@cogsci .ed.ac.ukwrote in message news
I think that's the truth of the matter.
>In article <g2hj1r$mse$1@r egistered.motza rella.org>,
>Richard <rgrdev@gmail.c omwrote:
>>
>[...]
>>
>I am simply pointing out that though there may be no objection to
>re-using a parameter variable *because it's a parameter*, there may be
>other reasons to object to re-using it. And because parameter
>variables usually have a name indicating their purpose, that often
>means that those other reasons apply.
>>
>Richard <rgrdev@gmail.c omwrote:
>>
>>>>I really am not interested in that. Its effectively a local
>>>>variable and
>>>>I have never seen anyone object, in the real world, to it being
>>>>manipulated .
>>>>variable and
>>>>I have never seen anyone object, in the real world, to it being
>>>>manipulated .
>>I'm not sure who you are addressing this too so I will refrain from
>>commenting further.
>>commenting further.
>I am simply pointing out that though there may be no objection to
>re-using a parameter variable *because it's a parameter*, there may be
>other reasons to object to re-using it. And because parameter
>variables usually have a name indicating their purpose, that often
>means that those other reasons apply.
>>
modifying them.
int send(unsigned char *txbuf, size_t bytes_to_send)
{
int ret=0;
while (bytes_to_send) {
ret = low_level_send( txbuf,bytes_to_ send);
if (ret 0) {
bytes_to_send -= ret;
txbuf += ret;
}
}
return ret;
}
The above is a simplification of a real and very important function in
one of my companies major applications. The real function has error
checking and low_level_send is actually a system-specific function which
is not guaranteed to send all of the data and return the amount of data
it sent. There are other ways it could be implemented, but this is
approximately how I did it.
--
Flash Gordon
Comment