gcc has a handy built-in for you (also available with clang), which allows to directly compare types:
int __builtin_types_compatible_p (type1, type2)
This built-in function returns 1 if the unqualified versions of the types type1 and type2 (which are types, not expressions) are compatible, 0 otherwise. The result of this built-in function can be used in integer constant expressions.
http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
This built-in is used for type-specific dispatch and type checking in linux kernel, to name one example.
To get the types out of expressions, you can rely on typeof()
statement, to the tune:
__builtin_types_compatible_p (typeof(n), int)