const是在CGFloat之前还是之后?

时间:2011-05-03 20:43:08

标签: objective-c c floating-point const cgfloat

甚至重要吗? Const before or const after?我猜我是否在const之前或之后放CGFloat它会使CGFloat的值保持不变,但指针呢?这是否适合Objective-C:

// Example.h

extern CGFloat const kPasscodeInputBoxWidth;


// Example.m

CGFloat const kPasscodeInputBoxWidth = 61.0f;

2 个答案:

答案 0 :(得分:21)

可以在之前或之后进行。在指针的情况下,重要的是const是否在星号之前或之后结束:

const int *a;    // pointer to const int -- can't change what a points at
int const *a;    // same

int *const a;    // const pointer to int -- can't change the pointer itself.
                 // Note: must be initialized, since it can't be assigned.

答案 1 :(得分:5)

没关系(我一直使用前者,但我想这是风格问题):

const CGFloat kPasscodeInputBoxWidth = 61.0;
CGFloat const kPasscodeInputBoxWidth = 61.0;

至少在CGFloat的当前版本中,它只是double的typedef,所以就像使用常规原始数据类型一样。对于指针,const的放置将决定它是指针还是恒定的值,因此它确实很重要。