Look at the code today to see an interesting dongdong, that is, the Linux kernel also has the Min function, but its implementation is very strange, first posted out:
The procedures in Linux/types.h are as follows:
View Plaincopy to Clipboardprint?
#ifndef _types_h_
#define _types_h_
#define ARRAY_SIZE (x) (sizeof (x)/sizeof ((x) [0]))
typedef unsigned char U8;
typedef unsigned short U16;
typedef unsigned int u32;
typedef unsigned long long u64;
#define MIN (x,y) ({/
typeof (x) _x = (x); /
typeof (Y) _y = (y); /
(void) (&_x = = &_y); /
_x < _y? _x: _y; })
#define MAX (X,y) ({/
typeof (x) _x = (x); /
typeof (Y) _y = (y); /
(void) (&_x = = &_y); /
_x > _y? _x: _y; })
#endif/* _types_h_ * *
#ifndef _types_h_
#define _types_h_
#define ARRAY_SIZE (x) (sizeof (x)/sizeof ((x) [0]))
typedef unsigned char U8;
typedef unsigned short U16;
typedef unsigned int u32;
typedef unsigned long long u64;
#define MIN (x,y) ({/
typeof (x) _x = (x); /
typeof (Y) _y = (y); /
(void) (&_x = = &_y); /
_x < _y? _x: _y; })
#define MAX (X,y) ({/
typeof (x) _x = (x); /
typeof (Y) _y = (y); /
(void) (&_x = = &_y); /
_x > _y? _x: _y; })
#endif/* _types_h_ * *
Others are common, but the middle (void) (&_x = = &_y) is strange, what is the use of this sentence?
Check the next network found:
(void) (&_x = = &_y) This sentence itself from the implementation of the program is completely a nonsense, its role is that we can not do such operations typeof (_x) ==typeof (_y), so deliberately judged their 2 address pointers are equal, is obviously not equal, But if the type of _x and _y is different, and the pointer type is different, 2 different pointer types are compared, and a compilation warning is thrown. That is to say Char *p; int *q; And then p==q, and this judgment because one is char* and one is int*, it generates a warning at compile time. Ingenious on the ingenious here.
This article from Csdn Blog, reproduced please indicate the source: http://blog.csdn.net/erazy0/archive/2010/03/31/5437910.aspx