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;
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With