【发布时间】:2020-09-11 09:15:46
【问题描述】:
- 我使用的是 GCC 编译器(版本 9.2.0)
- 我想在 C 中使用 typeof 函数,但它会引发错误(error: expected expression before 'typeof')
- 如果您需要更多信息,尽管问我。
int a = 5;
double b;
//the expected result is "0", but it raises an error instead...
printf("%d", typeof(a) == typeof(b));
【问题讨论】:
-
它引发错误的原因与
int == double引发错误的原因相同。 -
C++ 有
typeid可以做到这一点,但我认为 C 还没有。 -
@tadman - 更准确的 C++ 等效项是
decltype。 -
@StoryTeller-UnslanderMonica 更好,是的!
-
GCC 有
__builtin_types_compatible_p(TYPE1, TYPE2)。
标签: c gcc compiler-errors typeof