use this (they use two local variable):
#define min_t(type,x,y) ({ type __x=(x); type __y=(y); __x<__y?__x:__y; })
instead of:
#define min(x,y) ( (x) < (y) ? (x) : (y); )
because ,the second one hase side effect when do like this :
min(++ia, ++ib) –> ( (++ia) < (++ib) ? (++ia) : (++ib) )
has the side effect : the input Micro be ++ twice !
also,we can use this one :
#define min(x,y) ({
const typeof(x) _x=(x);
const typeof(y) _y=(y);
(void) (&_x=&_y);
_x < _y ? _x : _y;})
the function of typeof is to get the type of the input variable.and ,the (void) (&_x=&_y); is to check whether the two valiables’ type is the same .
digest from:《Linux设备驱动开发详解》 宋宝华 编著