<分区>
在C语言中,static const
和const static
在变量声明上有区别吗?
const static
给出 警告:'static' 不在声明的开头
。
这不是我的代码,我看到的所有其他问题都是关于 C++ 的,static
在那里有不同的含义。
<分区>
在C语言中,static const
和const static
在变量声明上有区别吗?
const static
给出 警告:'static' 不在声明的开头
。
这不是我的代码,我看到的所有其他问题都是关于 C++ 的,static
在那里有不同的含义。
最佳答案
限定符和说明符的顺序无关紧要。根据 C 2011 [N1570] 6.7.3 10:
… the order of type qualifiers within a list of specifiers or qualifiers does not affect the specified type.
和 6.7.2 2:
… the type specifiers may occur in any order, possibly intermixed with the other declaration specifiers.
但是,该标准在 6.11.5 中将在其他说明符或限定符之后使用存储类说明符描述为已过时:
The placement of a storage-class specifier other than at the beginning of the declaration specifiers in a declaration is an obsolescent feature.
“过时”是指该功能可能会在未来的标准修订中被考虑撤回(根据介绍第 2 段)。因此,针对使用 const static
发出警告的编译器建议进行更改,以帮助为 future 版本的 C 准备源代码。
关于c - 静态常量与常量静态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49173034/