[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20070425082028.8ece3094.randy.dunlap@oracle.com>
Date: Wed, 25 Apr 2007 08:20:28 -0700
From: Randy Dunlap <randy.dunlap@...cle.com>
To: Richard Knutsson <ricknu-0@...dent.ltu.se>
Cc: Jiri Bohac <jbohac@...e.cz>, akpm@...l.org,
linux-kernel@...r.kernel.org
Subject: Re: [RFC][PATCH] fix abs() macro to work with types wider than int
On Fri, 20 Apr 2007 14:44:38 +0200 Richard Knutsson wrote:
> Randy Dunlap wrote:
> > On Thu, 19 Apr 2007 11:23:39 +0200 Jiri Bohac wrote:
> >
> >
> >> Hi,
> >>
> >> is there any reason to use an explicit int instead of a typeof in
> >> the abs() macro? The current implementation will return bogus
> >> results when used with longs.
> >>
> >
> > I think it's like it is just to be consistent with abs() in C,
> > which also contains labs() and llabs().
> >
> We actually had labs() before (few months ago), but since it was not
> used, and if it would it seemed better to just fix abs(), it was
> removed. So I think this is the appropriate way to go.
Sounds like when someone actually needs labs() or llabs()
they can submit a patch for however they would like to use it.
> >> How about changing the int to a typeof like this?:
> >>
> >>
> >>
> >> Fix the abs() macro to work with wider types than int.
> >>
> >> Signed-off-by: Jiri Bohac <jbohac@...e.cz>
> >>
> >> --- linux-2.6.21-rc5.orig/include/linux/kernel.h
> >> +++ linux-2.6.21-rc5/include/linux/kernel.h
> >> @@ -89,7 +89,7 @@ extern int cond_resched(void);
> >> #define might_sleep_if(cond) do { if (cond) might_sleep(); } while (0)
> >>
> >> #define abs(x) ({ \
> >> - int __x = (x); \
> >> + typeof(x) __x = (x); \
> >> (__x < 0) ? -__x : __x; \
> >> })
---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists