typecheck()
		
		
		
		Jump to navigation
		Jump to search
		
It is possible (although not straightforward) to typecheck an expression (and get warnings, etc.) without actually compiling the expression.
Definition:
#define typecheck(...) \
    do { \
        (void) __builtin_constant_p(__VA_ARGS__); \
    } while(0)
Usage:
void foo()
{
    int i = -1;
    unsigned int j = 1;
    // warning: comparison of integer expressions of different signedness: 'int' and 'unsigned int'
    typecheck(i != j);
}
Note: this only works in gcc/clang.