When you use a macro, enclose each parameter in parentheses and enclose the overall definition of the macro; In general, do not use the self-increment or decrement operator in a macro.
[1] Maximum value
#define MIN (x, Y) (((x) < (y))? (x): (y))
Ask the lesser of the two
#define MAX (x, y) ((x) > (y))? (x): (y))
Ask the larger of the two
#define MAX3 (X,Y,Z) max (Max (x,y), z)
The larger among the three
[2] Shift
#define SHIFT (value, N) (((n) > 0)? ((value) << (n))
: ((value) >>-(n))
Shift operation on value, n > 0 left SHIFT, N < 0 right Shift
[3] Character
#define IS_LOWER_CASE (x) ((x) >= ' a ') && ((x) <= ' z '))
Judge Lowercase
#define IS_UPPER_CASE (x) ((x) >= ' A ') && ((x) <= ' Z '))
Judge Uppercase
#define Is_alphabetic (c) (Is_lower_case (c) | | Is_upper_case (c))
Judging letters
#define IS_DIGIT (x) (((x) >= ' 0 ') && ((x) <= ' 9 '))
Judging numbers
#define Is_special (c) (!is_digit (c) &&!is_alphabetic (c))
Judging special characters
[4] Take absolute value
#define ABSOLUTE_VALUE (x) ((x) < 0)?-(x): (x))
[5] #运算符
#define DPRINT (expr) printf (#expr "=%.1fn", expr)
#参数: Will output the quoted parameter value;
Dprint (1.0/2.0); will output: 1.0/2.0=0.5;
[6]# #运算符
#define XPRINT (Front,back) Front # back
XPRINT (x,1); will output: x1
[7] Judging leap years
#define LEAP_YEAR (x) ((x)% 4 = 0 && (x)% 100!= 0) | | ((x)% 400 = 0))
[8] integer val takes bit of nth bit
#define BIT (Val,n) (((VAL) >> (N)) & 1? 1:0)
This article is from the "Zi Postman" blog, please be sure to keep this source http://zhangjunhd.blog.51cto.com/113473/54402