Re: Re-use the argument?



"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

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

.



Relevant Pages

  • Re: Whats wrong with my code?
    ... Thanks Richard. ... >>I get this error message when it tries to insert data into the 'Printers' ... >> Const adLockOptimistic = 3 ... >> For Each objItem In colCompItems ...
    (microsoft.public.scripting.vbscript)
  • Re: Comments ok?
    ... Thanks for the rapid reply Richard - and sorry for the // style muck. ... That, alas, doesn't mean it's const. ... // Could it be a single char, an unitialised pointer, an illegal ...
    (comp.lang.c)
  • Re: When to use const modifier?
    ... Richard wrote: ... that const and restrict are of minor value, ... Intra-Procedural Analysis optimizer of the compilers I use. ... with regards to const, I find it hard to believe that you can not find ...
    (comp.lang.c)
  • Re: Re-use the argument?
    ... unsigned Func(unsigned const x) ... Generally it is considered bad form to modify an argument to a function. ... Free games and programming goodies. ...
    (comp.lang.c)
  • Re: "const void * const"
    ... In your code, (void * const, ... Richard ... Prev by Date: ...
    (microsoft.public.vc.language)