“(void)(&_min1 == &_min2)"的作用是什么?在 kernel.h 的 min 宏中? [英] What is the function of "(void) (&_min1 == &_min2)" in the min macro in kernel.h?
问题描述
在 kernel.h min 定义为:
In kernel.h min is defined as:
#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.
但是声明没有副作用!
但是:当 x
和 y
的类型不兼容时,它会强制编译器发出诊断信息.
请注意,使用 _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.
所以,这就是它的作用.它在编译时验证 x
和 y
的类型是否兼容.
So, that is what it does. It validates, at compile time, that the types of x
and y
are compatible.
这篇关于“(void)(&_min1 == &_min2)"的作用是什么?在 kernel.h 的 min 宏中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!