The timer API: size or type safety?
Posted Dec 8, 2006 11:46 UTC (Fri) by viro
In reply to: The timer API: size or type safety?
Parent article: The timer API: size or type safety?
Heh... The current version in my tree actually gets you a constant
arithmetic expression. It's built around the following:
#define check_callback_type(f,x) (sizeof((0 ? (f)(x) : (void)0), 0))
Feel free to torture students with it... It actually checks even
more - namely, that f returns void. And since it never evaluates
f or x, we are free to use it in macros without any concerns about
side effects. Can be used in global initializers, too (and yes,
it _is_ valid C99; we get past the constraints since the expression
that appears to be problematic is an argument of sizeof and doesn't
have a variably-modified type).
to post comments)