来自标准N1570 6.7.8:
A
typedef
declaration does not introduce a new type, only a synonym for the type so specified.
所以我预计不可能这样写:
typedef t;
t *t_ptr;
它应该无法编译,因为没有类型可以引入同义词。但没关系:Demo .那么这是什么意思,为什么会编译?
最佳答案
这依赖于这样一个事实,即缺少类型规范默认为 int
。
所以,你的陈述
typedef t;
与
相同 typedef int t;
有了适当的警告级别,编译器会发出警告:
warning: type defaults to ‘int’ in declaration of ‘t’ [-Wimplicit-int]
typedef t;
^
也就是说,不要依赖这种行为,“implicit int”规则自 C99
以来已经过时。
关于c - 没有类型的 typedef 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53512585/