All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Knutsson <ricknu-0@student.ltu.se>
To: kernel-janitors@vger.kernel.org
Subject: Re: [KJ] [RFC] Regarding abs() and labs()
Date: Sat, 03 Feb 2007 02:52:40 +0000	[thread overview]
Message-ID: <45C3F8F8.2000807@student.ltu.se> (raw)
In-Reply-To: <45C3E1C8.2040105@student.ltu.se>

Randy Dunlap wrote:
> On Sat, 03 Feb 2007 03:22:29 +0100 Richard Knutsson wrote:
>
>   
>> Randy Dunlap wrote:
>>     
>>> On Sat, 03 Feb 2007 02:13:44 +0100 Richard Knutsson wrote:
>>>
>>>   
>>>       
>>>> Hello all
>>>>
>>>> Just took a look at abs() and can not understand why it seem so 
>>>> overcomplicated. Why not just:
>>>>
>>>> #define abs(x)	((x) < 0) ? -(x) : (x))
>>>>     
>>>>         
>>> It's almost that simple.  It just adds a local __x so that
>>> 'x' won't be evaluated multiple times as it would in the simpler
>>> version.  Multiple evaluations (of an expression) (that could
>>> have side effects) would take more CPU horsepower and could
>>> have bad side effects as well.
>>>   
>>>       
>> You mean if x is ex a + b? In such case; why not use typeof instead of int?
>>     
>
> I suppose that would make sense if we have a need for abs(various types),
> but until we do, just using: int __x; is good enough.
>   
Mm, true. Don't mess with something that is not broken (if not for the 
fun of it).
But that really leaves labs() hanging. I guess it was added because it 
is in gcc's stdlib.h.
>> What kind of side-effects are you talking about?
>>     
>
> The usual kind that affect computer software.  E.g.:
>
> 	a = abs(var1++);
>   
Oh thanks, good "eye-opener" :)

Thanks for clearing things up
Richard Knutsson

_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors

      parent reply	other threads:[~2007-02-03  2:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-03  1:13 [KJ] [RFC] Regarding abs() and labs() Richard Knutsson
2007-02-03  1:44 ` Randy Dunlap
2007-02-03  2:22 ` Richard Knutsson
2007-02-03  2:34 ` Randy Dunlap
2007-02-03  2:52 ` Richard Knutsson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=45C3F8F8.2000807@student.ltu.se \
    --to=ricknu-0@student.ltu.se \
    --cc=kernel-janitors@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.