ma1*_*w28 15 c floating-point const objective-c cgfloat
它甚至重要吗?Const之前还是const之后?我猜测我是const在CGFloat它之前还是之后使它的值CGFloat变为常量,但指针呢?这是否适合Objective-C:
// Example.h
extern CGFloat const kPasscodeInputBoxWidth;
// Example.m
CGFloat const kPasscodeInputBoxWidth = 61.0f;
Run Code Online (Sandbox Code Playgroud)
Jer*_*fin 22
它可以在之前或之后进行.在指针的情况下,重要的是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.
Run Code Online (Sandbox Code Playgroud)
没关系(我一直使用前者,但我想这是风格问题):
const CGFloat kPasscodeInputBoxWidth = 61.0;
CGFloat const kPasscodeInputBoxWidth = 61.0;
Run Code Online (Sandbox Code Playgroud)
至少在当前的演绎中CGFloat,它只是一个typedef double,就像你使用常规的原始数据类型一样.对于指针,const的放置将决定它是指针还是常量值,因此它确实很重要.