c - 静态常量与常量静态

标签 c static constants

<分区>

在C语言中,static constconst 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/

相关文章:

c - 存储指向 strsep() 返回值的指针

将多个十六进制数组复制到一个 C 中

c - 将指向结构的指针分配给变量

c - 有没有办法从 C 中收到的数据包中读取 url?

c++ - 如何将 Eclipse C++ 项目构建为库并将其添加到另一个项目

android - Android 中的静态变量和低内存 - 几个问题

java - 另一个类的内部类的实例化

c++ - 解决 C++ 对临时对象的非常量引用的限制

ruby - 访问常量

swift - let 和 var Swift REPL 中 const 的重新声明无效