The file include/linux/typecheck.h of the Linux kernel 4.16 contains this code.
#define typecheck(type,x) \
({ type __dummy; \
typeof(x) __dummy2; \
(void)(&__dummy == &__dummy2); \
1; \
}
which checks if x is the same type as the parameter type.
But I can’t understand the line:
(void)(&__dummy == &__dummy2);
How does comparing the first address of both variables help?
Comparing pointers with incompatible types is a constraint violation and requires the compiler to issue a diagnostic. See 6.5.9 Equality operators:
and 5.1.1.3 Diagnostics: