分宏kernel.h [英] min macro in kernel.h
问题描述
在 kernel.h 分钟被定义如:
#define min(x, y) ({ \
typeof(x) _min1 = (x); \
typeof(y) _min2 = (y); \
(void) (&_min1 == &_min2); \
_min1 < _min2 ? _min1 : _min2; })
我不明白什么行(无效)(安培; _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.
但声明没有副作用!
不过:<EM>迫使编译器发出诊断时的类型 X
和是
是不兼容的。结果
注意与测试 _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
和是
是兼容。
So, I guess, that is what it does. It validates, at compile time, that the types of x
and y
are compatible.
这篇关于分宏kernel.h的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!