c - 没有类型的 typedef 是什么意思?

标签 c typedef

来自标准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/

相关文章:

c - 当你给一个 C 标准函数一个空字符串时会发生什么?

在 GCC 或 Cygwin 中创建 DLL?

c - 如何同时使用 scanf 和 fgets 读取文件

kill 命令后关闭文件

c++ - 了解如何使用带指针作为参数的typedef void函数

c - 在一个 block 中定义和声明结构与声明然后定义结构之间是否存在明显差异?

c - 如何将 typedef 结构转换为 uint8_t 参数

c++ - "typedef char CHAR[10];"是什么意思?

c++ - GDB 不喜欢我的 typedef

C99条件返回值