Re: Re-use the argument?



"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.
.



Relevant Pages

  • Re: Making C# properties act like member variables
    ... > return const objects so that I wouldn't have to worry about the client ... > holds a reference to the FloatRgba version of diffuseColor and can modify ... it returns a new FloatRbga and change FloatRbga so that it is immutable. ... so you have to think about modifiability when designing the type not ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Using const qualifier
    ... But it returns a pointer through which you could modify the list. ... Do you use "const" to imply "I will not change this, ... const int *operate; ... constraint: typeofis typeof; ...
    (comp.lang.c)
  • RE: const and call by value parameters
    ... "Mark" wrote: ... > void myobject::g ... you omit const in this case. ... MUST NOT modify its parameter, rather than when it DOESN'T modify ...
    (microsoft.public.vc.language)
  • Re: accessor member functions and const
    ... I want to be able to reference the returned ... const int& getValconst ... so one cannot modify the object via the reference. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: malloc questions
    ... T * const allocdef(unsigned const amount_elem) ... You cannot modify p, ... That's an interesting Chinese character in your name. ... a legacy encoding for traditional Chinese characters. ...
    (comp.lang.c)