lkml.org 
[lkml]   [2001]   [Aug]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [IDEA+RFC] Possible solution for min()/max() war
Date
On August 30, 2001 09:51 pm, David Weinehall wrote:
> On Thu, Aug 30, 2001 at 06:38:40PM +0200, Peter T. Breuer wrote:
> > "Linus Torvalds wrote:"
> > > What if the "int" happens to be negative?
> >
> > if sizeof(typeof(a)) != sizeof(typeof(b))
> > BUG() // sizes differ
> > const (typeof(a)) _a = ~(typeof(a))0
> > const (typeof(b)) _b = ~(typeof(b))0
> > if _a < 0 && _b > 0 || _a > 0 && b < 0
> > BUG() // one signed, the other unsigned
> > standard_max(a,b)
>
> <disgusting vomit-sound>Do you really want code like that in the
> kernel (yes, I know that there are code that can compete with it in
> ugliness</disgusting vomit-sound>

Well, loook, if the signedness and widths match all the tests get optimized
out as constant expressions, if they don't it barfs with BUG and the author
has to insert specify saner types for the input variables. It's nice.

This accomplishes what 3arg_min/max set out to do without messing up the
syntax.

--
Daniel
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:01    [W:0.201 / U:6.192 seconds]
©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site