lkml.org 
[lkml]   [2001]   [Sep]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [IDEA+RFC] Possible solution for min()/max() war
Date
"Bill Pringlemeir wrote:"
> compile_time_assert( (_x - 1 > 0 && _y - 1 > 0) \
> || (_x - 1 < 0 && _y - 1 < 0)); \
>
> This should prevent all cases where the __MIN(x,y) macro can screw up
> due to sign issues (on that machine). If you do this, the `sizeof'

Eh? "0" is a signed integer constant. So your comparisons force promotion
to int when x is smaller size. I'm not sure what type

"unsigned foo - signed int"

would have either! It seems to me that you are making things very
murky, which is precisely what you want to avoid.

> check isn't needed. A MIN(int, long) etc should probably be ok. The
> only caveats are the promotion in the __MIN itself create a sign
> mismatch.
>
> However, if the `sizeof' check remains, then you don't have to worry
> about this and both versions are equivalent. Some other things to
> worry about is what if the type is already const? Maybe that works...

No parsum.

> What if you try `MIN(x,_x);'. I think that this is something that
> David took care of in the "3 arg min".

You can't take care of it. A macro is always vulnerable to name
clashes.


Peter
-
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:02    [W:1.322 / U:0.080 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site