diff options
Diffstat (limited to 'include/linux/kernel.h')
| -rw-r--r-- | include/linux/kernel.h | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h index ea28234bd480..cd9e83570b0b 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -115,9 +115,32 @@ static inline void console_verbose(void) ((unsigned char *)&addr)[1], \ ((unsigned char *)&addr)[0] -#define min(type,x,y) \ +/* + * min()/max() macros that also do + * strict type-checking.. See the + * "unnecessary" pointer comparison. + */ +#define min(x,y) ({ \ + const typeof(x) _x = (x); \ + const typeof(y) _y = (y); \ + (void) (&_x == &_y); \ + _x < _y ? _x : _y; }) + +#define max(x,y) ({ \ + const typeof(x) _x = (x); \ + const typeof(y) _y = (y); \ + (void) (&_x == &_y); \ + _x > _y ? _x : _y; }) + +/* + * ..and if you can't take the strict + * types, you can specify one yourself. + * + * Or not use min/max at all, of course. + */ +#define min_t(type,x,y) \ ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; }) -#define max(type,x,y) \ +#define max_t(type,x,y) \ ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; }) #endif /* __KERNEL__ */ |
