what's the help of "unnecessary" pointer comparison

时间:2021-03-15 10:33:50

引述自http://c-programming.itags.org/q_c-programming-language_191518.html

源代码中的宏min中使用了

 (void) (&_x == &_y); 

(   c89不支持typeof   )

有如下解释

Assuming (as the name "typeof" implies) that _x has the same type as

x, and _y has the same type as y, comparing the addresses of _x and _y

is legal if and only if they have the same type. The result of the

comparison is irrelevant (and it's discarded anyway); the point is to

force the compiler to reject an invocation of the macro if the

arguments' types don't match.