c++ - 我们可以在声明中的任何位置放置 "typedef"说明符吗?

标签 c++ c language-lawyer typedef storage-class-specifier

typedef 说明符的语法:

typedef <existing_name> <alias_name>

例如:

typedef long unsigned int Int;

一切正常。

但是,如果我将 typedef 放在声明中的任何位置,就像这样:

long unsigned typedef int Int;

然后,它也可以正常工作。

为什么?我们可以将 typedef 放在声明中的任何位置吗?

最佳答案

首先,引自 §6.11.5,“ future 的语言方向”

1 The placement of a storage-class specifier other than at the beginning of the declaration specifiers in a declaration is an obsolescent feature.

所以,不要依赖这个,因为它可能在未来被移除。


也就是说,要了解其工作原理,请查看 C11 标准第 §6.7.2 章:

[...] the type specifiers may occur in any order, possibly intermixed with the other declaration specifiers.

从 §6.7.1,我们知道 typedef 是一个存储类说明符(一种特殊的声明说明符),所以它可以放在类型说明符之后(或之前)(< em>即,可以混合使用)。它不会改变任何东西。

关于c++ - 我们可以在声明中的任何位置放置 "typedef"说明符吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45750621/

相关文章:

c++ - GTK 滚动窗口 - 滚动到底部

c - 为什么输出是这样的?

c++ - 使用来自元函数的 typedef 声明成员函数

c++ - 难以置信的快速 C++ 委托(delegate)和不同的翻译单元

c++ - boost::any 如何检查空值/未定义值

C++/SDL 渲染文本

c++ - Boost 多精度舍入模式

c++ - 什么是 C 中的通用库?

c - 如何在 C 中进行 GUI 编程?

c++ - C++ 标准中 "as if"规则的声明或基础在哪里?