All of lore.kernel.org
 help / color / mirror / Atom feed
* [KJ] [RFC] Regarding abs() and labs()
@ 2007-02-03  1:13 Richard Knutsson
  2007-02-03  1:44 ` Randy Dunlap
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Richard Knutsson @ 2007-02-03  1:13 UTC (permalink / raw)
  To: kernel-janitors

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))

and skip labs() (not used anyway)
+ it gives a warning with -W if x is of a unsigned type ("condition is 
always false" or similar).
But remember to use %u when printing an unsigned, took me a while before 
I understood how an unsigned could contain a "negative" value :)

Happy weekend
Richard Knutsson

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

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

end of thread, other threads:[~2007-02-03  2:52 UTC | newest]

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