假设 T
是任意类型,我们正在谈论 Objective-C。那有什么区别呢
static T const x = ....
和
static const T x = ....
?
最佳答案
它们是一样的。
关于 const
的一些背景知识:
Objective-C,就像 C,使用 Clockwise/Spiral Rule .在变量(foo)的左侧只有修饰符的情况下,您会从右向左读取内容:
int * const * var;
读作:var 是指向整型常量指针的指针。
然而 const
在第一种类型之前或之后具有相同的效果:
int const var; // constant integer
const int var; // constant integer, same as above
相反,
static
会影响整个变量:变量是静态的,而不是它指向的元素或其他任何东西:指向整数的指针可以同时用于指向静态整数, 或自动整数而没有区别,并且 C 不提供语法来声明仅能指向静态变量(或自动变量)的指针。
static int * x; // x is a static pointer to integer
int static * y; // as above y is a static pointer to integer
int * static z; // THIS SYNTAX IS NOT ALLOWED
// but if it was, it would mean the same thing
出于这个原因,我更喜欢将它放在任何 const
修饰符之前,但这实际上并不重要。
static const int * const * x; // this is what I do
关于iphone - static T const 和 static const T 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4666435/