From: Richard Knutsson <ricknu-0@student.ltu.se>
To: Randy Dunlap <randy.dunlap@oracle.com>
Cc: Jiri Bohac <jbohac@suse.cz>, akpm@osdl.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC][PATCH] fix abs() macro to work with types wider than int
Date: Fri, 20 Apr 2007 14:44:38 +0200 [thread overview]
Message-ID: <4628B5B6.90303@student.ltu.se> (raw)
In-Reply-To: <20070419084339.418dbe69.randy.dunlap@oracle.com>
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.
>
>> 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@suse.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; \
>> })
>>
>>
>>
>>
next prev parent reply other threads:[~2007-04-20 12:47 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-19 9:23 [RFC][PATCH] fix abs() macro to work with types wider than int Jiri Bohac
2007-04-19 15:43 ` Randy Dunlap
2007-04-20 12:44 ` Richard Knutsson [this message]
2007-04-25 15:20 ` Randy Dunlap
2007-04-25 15:26 ` John Anthony Kazos Jr.
2007-04-25 15:38 ` Randy Dunlap
2007-04-25 23:42 ` John Anthony Kazos Jr.
2007-04-25 18:24 ` linux-os (Dick Johnson)
2007-04-25 20:05 ` Andreas Schwab
2007-04-25 20:30 ` linux-os (Dick Johnson)
2007-04-25 21:57 ` Andreas Schwab
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=4628B5B6.90303@student.ltu.se \
--to=ricknu-0@student.ltu.se \
--cc=akpm@osdl.org \
--cc=jbohac@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=randy.dunlap@oracle.com \
/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.