(void) (&x = = &y) Magical

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:

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

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.