public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC][PATCH] fix abs() macro to work with types wider than int
@ 2007-04-19  9:23 Jiri Bohac
  2007-04-19 15:43 ` Randy Dunlap
  0 siblings, 1 reply; 11+ messages in thread
From: Jiri Bohac @ 2007-04-19  9:23 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel

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.

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;		\
 	})
 



-- 
Jiri Bohac <jbohac@suse.cz>
SUSE Labs, SUSE CZ


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2007-04-25 23:42 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox