How do I write a macro CHECK(a, b) that generates compilation error when the two pointers a & b have different base type.
CHECK((int*)0, (char*)0) -> compilation error
CHECK((int*)0, (int*)0) -> works
I’m looking for some C89 code, but C99 + gcc extensions will also do.
EDIT now works for any type, not just pointers
Something more or less lifted from the linux kernel, using the GCC extension
typeof().This generates a warning at compile time, it also works for integer pointer types