【发布时间】:2016-02-21 04:12:23
【问题描述】:
以下代码来源于include/linux/typecheck.h:
/*
* 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; \\ <---- Why here is a 1;?
})
/*
* Check at compile time that 'function' is a certain type, or is a pointer
* to that type (needs to use typedef for the function type.)
*/
#define typecheck_fn(type,function) \
({ typeof(type) __tmp = function; \
(void)__tmp; \
})
1; 有什么不同吗?另外,一个块如何“评估为 1”?
【问题讨论】:
标签: c linux-kernel macros