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
"A month of sundays ago Bill Pringlemeir wrote:"
> Otherwise, I think we have independently came up with the same thing
> and the `error' throwing can of course be changed to whatever.

If you are interested, the last version I had is the following. The
compile_time_assert is linus' idea. We had an illegal assembler
statement there originally, containing the line number and the
error statement. One or the other will do until gcc gets the
__builtin_ct_assert() function.

#define compile_time_assert(x) \
do { switch (0) { case 0: case (x) != 0: ; } } while (0)
#define __MIN(x,y) ({\
typeof(x) _x = x; \
typeof(y) _y = y; \
_x < _y ? _x : _y ; \
})
#define MIN(x,y) ({\
const typeof(x) _x = ~(typeof(x))0; \
const typeof(y) _y = ~(typeof(y))0; \
compile_time_assert(sizeof(_x) == sizeof(_y));\
compile_time_assert( (_x > (typeof(x))0 && _y > (typeof(y))0) \
|| (_x < (typeof(x))0 && _y < (typeof(y))0)); \
__MIN(x,y); \
})
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    [from the cache]
©2003-2011 Jasper Spaans