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/