Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why compare address in this implementation of min? [duplicate]

Tags:

c

The implementation of min function here is done as:

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

What is the point of the 4th line?

Why do this: (void) (&_min1 == &_min2); ?

like image 957
BЈовић Avatar asked Jan 26 '17 14:01

BЈовић


1 Answers

It generates a warning if x and y have different types:

int i;
long j;
(void) (&i == &j);

The compiler says:

warning: comparison of distinct pointer types lacks a cast
like image 181
rom1v Avatar answered Nov 11 '22 08:11

rom1v