Min and Max functions in the Linux kernel __oracle

Source: Internet
Author: User
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:
/*
* min ()/max () macros that also do
* Strict type-checking. The
* "Unnecessary" pointer comparison.
*/
#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; })

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 executes the procedure to say completely is Div:eq (0) > Div:eq (3) > Table:eq (2) > Tbody:eq (0) > Tr:eq (0) > td:eq (0) > Div:eq (0) > #content: eq (0) > Br:eq (+) "anchortype=" Previous "jquery1251853974125=" 6 "> sentence
Nonsense, it is in itself that we can not do such operations typeof (_x) ==typeof (_y), so deliberately judged their 2 address pointers are equal, it is obviously impossible to equal, but if the _x and _y type is not the same, its pointer type will be different, 2 different pointer types for comparison operations, 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.

In addition, why to define two local variable _x,_y, the function is as follows:
If this is defined as follows:
#define MIN (A,b) (((a) < (b))? (a): (b))
Imagine:
Min (++a,++b) ==> (++a) < (++B)? (++a): (++b)
Is there a problem, the incoming parameters were added two times.
Defined as the above so there will be no problem, hehe

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.