edelaney05
edelaney05

Reputation: 6997

"static" keyword for global variables - What's the scope limited to?

Prefixing a variable declared outside of any scope with the keyword static prevents that variable from being externally accessible. However, does it limit the scope from a category using it?

Foo.m
@implementation Foo

static void* FooContext = &FooContext;

- (void)methodThatUsesFooContext { ... }

@end


Foo+SpecialSauce.h
@implementation Foo (Special Sauce)

- (void)anotherMethodThatWouldLikeToUseFooContext { ... }

@end

Upvotes: 1

Views: 307

Answers (1)

mipadi
mipadi

Reputation: 410732

Static variables declared at the top-level of a file (i.e., outside of any functions or method calls) are visible to anything within that file.

Upvotes: 1

Related Questions