Re: Re-use the argument?



"Malcolm McLean" <regniztar@xxxxxxxxxxxxxx> writes:

"Richard" <rgrdev@xxxxxxxxx> wrote in message
"Malcolm McLean" <regniztar@xxxxxxxxxxxxxx> writes:

"Tomás Ó hÉilidhe" <toe@xxxxxxxxxxx> wrote in message news:

Which of these functions would you go with?

unsigned Func(unsigned const x)
{
return 3*x - 2;
}

or:

unsigned Func(unsigned x)
{
x *= 3;
x -= 2;

return x;
}

Generally it is considered bad form to modify an argument to a
function. It makes things a bit more difficult to read.

What a load of nonsense. If its not a const its no more than a local
variable.

There's a previous thread on the subject

Newsgroups: comp.lang.c
From: Morgan Cheng <mo...@xxxxxxxxxxxxx>
Date: Tue, 19 Jul 2005 09:41:26 +0800
Local: Tues, Jul 19 2005 2:41 am
Subject: Should function argument be changed in function body?

I think this link should lead to it
http://groups.google.com/group/comp.lang.c/msg/3ac943f1b7a6c3c5

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. e.g it might be a date representing a proposed day for a
task. I would see no issue with updating the parameter to a new more
suitable date and then returning it. Still, all to their own as they say.

.



Relevant Pages

  • Re: Exception Handling and Refactoring Question ...
    ... An exception object needn't be protected using const for the ... > No, it is not nonsense. ...
    (comp.lang.cpp)
  • Re: Re-use the argument?
    ... Generally it is considered bad form to modify an argument to a ... What a load of nonsense. ... If its not a const its no more than a local variable. ...
    (comp.lang.c)
  • Re: type of "string"
    ... 'const' was an invention of Bjarne Stroustrup's for C++. ... an apparently good anti-optimisation idea but one with so little semantic requirement as to be virtually useless. ... have an appropriate newsgroups line in your header for your mail to be seen, ...
    (comp.lang.c.moderated)
  • Re: Casting off const - any side effects?
    ... which take a const pointer - because they will not modify the data - ... modify and it doesn't. ... So the lookup is const, but the result may be used by the ... have an appropriate newsgroups line in your header for your mail to be seen, ...
    (comp.lang.c.moderated)
  • Re: Casting off const - any side effects?
    ... which take a const pointer - because they will not modify the data - ... modify and it doesn't. ... So the lookup is const, but the result may be used by the ... have an appropriate newsgroups line in your header for your mail to be seen, ...
    (comp.lang.c.moderated)