Tag: 型安全

在C中编译多个类型的时间检查?

目前我有一个宏来检查一个值是一个类型。 #define CHECK_TYPE_INLINE(val, type) \ ((void)(((type)0) != (0 ? (val) : ((type)0)))) 在某些情况下,这对于能够对宏args进行类型检查很有用。 但是如果我要检查多种类型呢? 例如,检查它是否为struct Foo *或struct Bar * 。 例, static inline _insert_item(struct List *ls, void *item) { /* function body*/ } /* type-checked wrapper */ #define insert_item(ls, item) \ (CHECK_TYPE_ANY(item, struct Foo *, struct Bar *), \ _insert_item(ls, item)) 这有什么好方法吗?