Re: Re-use the argument?



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

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

.



Relevant Pages

  • Re: Programming to Beat the Odds in Gaming
    ... The problem it it is that much more difficult to modify to add your own functions. ... Again, you could add procedures, but this creates major complications. ... Free games and programming goodies. ...
    (comp.programming)
  • Re: Re-use the argument?
    ... "Richard" wrote in message ... If its not a const its no more than a local variable. ... Free games and programming goodies. ...
    (comp.lang.c)
  • 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)