user3740387
user3740387

Reputation: 367

Cant understand the implementation of max function in the linux kernel

What's the significance of (void) (&_max1 == &_max2); in the following definition of max found in Linux/tools/lib/lockdep/uinclude/linux/kernel.h?

#define max(x, y) ({                            \
      typeof(x) _max1 = (x);                  \
      typeof(y) _max2 = (y);                  \
      (void) (&_max1 == &_max2);              \
      _max1 > _max2 ? _max1 : _max2; })

Upvotes: 3

Views: 250

Answers (1)

Stephen Kitt
Stephen Kitt

Reputation: 2881

It helps the compiler detect invalid uses of max(), i.e. with non-comparable x and y. As Sukminder points out, the == check is only used at compile time, it doesn't end up in the resulting binary.

Upvotes: 1

Related Questions