“(void)(& _min1 ==& _min2)"的功能是什么?在kernel.h的min宏中? [英] What is the function of "(void) (&_min1 == &_min2)" in the min macro in kernel.h?

查看:134
本文介绍了“(void)(& _min1 ==& _min2)"的功能是什么?在kernel.h的min宏中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

kernel.h 最小值定义为:

#define min(x, y) ({                \
    typeof(x) _min1 = (x);          \
    typeof(y) _min2 = (y);          \
    (void) (&_min1 == &_min2);      \
    _min1 < _min2 ? _min1 : _min2; })

我不明白(void) (&_min1 == &_min2);行的作用.是某种类型检查还是什么?

I don't understand what the line (void) (&_min1 == &_min2); does. Is it some kind of type checking or something?

推荐答案

语句

(void) (&_min1 == &_min2);

是保证的禁止操作".因此,它存在的唯一原因就是它的副作用.

is a guaranteed "no-op". So the only reason it's there is for its side effects.

但是该声明没有副作用!

But the statement has no side effects!

但是:xy类型不兼容时,它会强制编译器发出诊断信息.
请注意,使用_min1 == _min2进行测试会将这些值之一隐式转换为另一种类型.

However: it forces the compiler to issue a diagnostic when the types of x and y are not compatible.
Note that testing with _min1 == _min2 would implicitly convert one of the values to the other type.

所以,我想这就是它的作用. 它在编译时验证xy的类型是否兼容.

So, I guess, that is what it does. It validates, at compile time, that the types of x and y are compatible.

这篇关于“(void)(&amp; _min1 ==&amp; _min2)"的功能是什么?在kernel.h的min宏中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆