Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does const go before or after CGFloat?

Does it even matter? Const before or const after? I'm guessing that whether I put const before or after CGFloat it makes the value of CGFloat constant, but what about the pointer? Is this right for Objective-C:

// Example.h

extern CGFloat const kPasscodeInputBoxWidth;


// Example.m

CGFloat const kPasscodeInputBoxWidth = 61.0f;
like image 948
ma11hew28 Avatar asked May 03 '11 20:05

ma11hew28


2 Answers

It can go either before or after. In the case of a pointer, what matters is whether the const ends up before or after the asterisk:

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.
like image 67
Jerry Coffin Avatar answered Nov 04 '22 12:11

Jerry Coffin


It doesn't matter (I've always used the former, but I guess it's a matter of style):

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

At least in the current rendition of CGFloat, it's just a typedef of double, so do as you would with a regular primitive datatype. For pointers, the placement of const will determine if it's the pointer or the value that is constant, so for that it does matter.

like image 6
Gustav Larsson Avatar answered Nov 04 '22 11:11

Gustav Larsson