3 ms·
What exactly is the typecheck macro doing here? I get that it compares the sizes of two pointer values but I don't know why and I feel like there is some C stan
by gshrikant 9y ago
What exactly is the typecheck macro doing here? I get that it compares the sizes of two pointer values but I don't know why and I feel like there is some C standard nuance involved here that I don't understand. Also, is the `sizeof` used to force evaluation at compile time?
- tbodt 9y agoThe type of == is always int, so the sizeof is sizeof(int), and the !! makes the result always be 1 (true). The entire purpose of the macro is to have the compiler warn if the types are incompatible.
- gshrikant 9y agoThanks! However, I still don't understand this completely. So the sizeof is there just to force evaluation of the comparison and because == can only be used among compatible types the compiler would warn? Why is the !! necessary then wouldn't sizeof(int) be enough as a "true" value?
- LukeShu 9y agoIt's to have the compiler produce a warning if the types aren't the same. __cmp_once produces such a warning, and they don't want the warning to go away if it decides to use plain __cmp instead of __cmp_once. It doesn't "do" anything otherwise; it always evaluates to "1".
- gshrikant 9y agoDoesn't the compiler produce a warning by default (on comparing a `char` and `int`, for example) when using -Wall?