Usually I use the first one to define const, but I don't know the difference of the following clearly.
static NSString* kFetcherCallbackThreadKey = @"_callbackThread";
static NSString* const kFetcherCallbackRunLoopModesKey = @"_runLoopModes";
NSString* const kFetcherRetryInvocationKey = @"_retryInvocation";
static const NSUInteger kMaxNumberOfNextLinksFollowed = 25;
const and #define both are used for handle constants in source code, but they few differences. #define is used to define some values with a name (string), this defined string is known as Macro definition in C, C++ while const is a keyword or used to make the value of an identifier (that is constant) constant.
1. fixed and invariable; unchanging. 2. continual or continuous; incessant. constant interruptions.
So in your question, "int const *" means that the int is constant, while "int * const" would mean that the pointer is constant. If someone decides to put it at the very front (eg: "const int *"), as a special exception in that case it applies to the thing after it.
The const keyword causes the identifier size to be allocated in the read-only memory. This means that the value of the identifier can not be changed by the executing program. MACROS are efficient than the const statements as they are not given any memory, being more Readable and Faster in execution!
In C, the static
keyword, used outside a function, is used to declare a symbol that will be accessible only from the file in which it's declared. Kind of «private» global variables.
The const keyword means «constant». Read, the value can't be modified. Note the two statements are different:
const int * x;
int * const x;
The first one defines a pointer to a constant integer (its value can't be modified, but it can point to something else). The second one defines a constant pointer to an integer (the pointer value can't be modified, but the value of the int may be). So you can perfectly have:
const int * const x;
So in your case:
static NSString* kFetcherCallbackThreadKey = @"_callbackThread";
A pointer to a NSString instance that will be accessible only from the file in which it's declared.
static NSString* const kFetcherCallbackRunLoopModesKey = @"_runLoopModes";
A constant pointer to a NSString instance that will be accessible only from the file in which it's declared.
NSString* const kFetcherRetryInvocationKey = @"_retryInvocation";
A constant pointer to a NSString instance that may be accessed from other files of your project.
static const NSUInteger kMaxNumberOfNextLinksFollowed = 25;
A constant integer that will be accessible only from the file in which it's declared.
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