Search code examples
iosobjective-cstaticexternlinkage

Scope of (const) variable when is not defined as extern or static


I have some constant variables which I want to be global, and some of them should be available only in the file where are defined. So I use extern and static keywords, like this:

extern const int kMaxHealth = 100;
static NSString * const kName = @"Name";

This is just an example, and those are defined in different files, so this is not a real situation...

But what is the scope of variable when is defined without modifiers, like this:

const int kMaxHealth = 100;

Is kMaxHealth extern now, or static, or have some other scope?


Solution

  • It has the same scope as a normal variable would without the const , but does not allow you to assign a new value to the variable.