我想做一个宏来判断给定的值是否是整数,我发现有些整数类型在使用_Generic
时是相互兼容的,所以它们不能都作为单独的_Generic
情况使用.
比如int
和int32_t
或
signed char
和int8_t
what is the rule on that? Is there a solution that w或ks with all platf或ms/compilers?
我当前的代码是:
#define is_integer(exp) \
_Generic(exp, \
int8_t: 1, \
int16_t: 1, \
int32_t: 1, \
int64_t: 1, \
uint8_t: 1, \
uint16_t: 1, \
uint32_t: 1, \
uint64_t: 1, \
default: 0)
However, it doesn't w或k with char
(goes to default), but w或ks with signed char
(goes to int8_t
).
Should I add char
as a separate _Generic
case? I'm afraid that some implementation typedef
s int8_t
to char
so it won't w或k, 或 are they not allowed to?