In the Linux kernel min (x, y) and max (x, y) macro definition

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

/linux/include/linux/Min kernel.h (x, y) and max (x, y) is defined as follows:

 1   #define min(x, y) ({ \
 2       typeof(x) _min1 = x; \
 3       typeof(y) _min2 = y; \
 4       (void) (&_min1 == &_min2); \
 5       _min1 <_min2 ? _min1 :  _min2; })
 6   
 7   #define max(x, y) ({ \
 8       typeof(x) _max1 = x; \
 9       typeof(y) _max2 = y; \
10      (void) (&_max1 == &_max2); \
11      _max1 > _max2 ? _max1 : _max2; }

The red line two role: to prevent various types of parameters were compared,

When the parameter types are not at the same time, the compiler will prompt: warning: comparison of distinct pointer types lacks a cast

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Simon at November 17, 2013 - 4:15 PM