/*
* Check at compile time that something is of a particular type.
* Always evaluates to 1 so you may use it easily in comparisons.
*/
#define typecheck(type,x) \
({ type __dummy; \
typeof(x) __dummy2; \
(void)(&__dummy == &__dummy2); \
1; \
})
#include <stdio.h>
#define typecheck(type,x) \
({ type __dummy; \
typeof(x) __dummy2; \
(void)(&__dummy == &__dummy2); \
1; \
})
int main()
{
int i = 18;
printf ("%d\n", typecheck (unsigned long, i));
return (0);
}
# gcc typecheck.c -o typecheck
typecheck.c: In function ‘main’:
typecheck.c:14: 警告:比较不相关的指针时缺少类型转换
# ./typecheck
1
type __dummy;
typeof(x) __dummy2;
(void)(&__dummy == &__dummy2);
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |