Does const go before or after CGFloat?

ma11hew28 picture ma11hew28 · May 3, 2011 · Viewed 12.8k times · Source

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;

Answer

Jerry Coffin picture Jerry Coffin · May 3, 2011

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.