Reputation: 47354
I'm debugging a legacy app and have encountered the following scenario
LegacySource.h
cFunctionModifyingSomeVariable()
LegacySource.c
static struct someVariable; //a custom struct
ObjectiveCImplementation.m
#import LegacySource.h
-(void)workWithLegacy {
cFunctionModifyingSomeVariable(); // modifies variable declared in C class
}
What is the effect of having a static struct from C imported into Objective-C?
Do all of my Objective-C classes share the same single instance of the static struct, or does every instance get their own? In other words, if I make 3 instances of ObjectiveCImplementation, would they modify the same variable, or would their effects be independent from each other?
Upvotes: 0
Views: 75
Reputation: 90621
The Objective-C code is not working with someVariable
, at all. It's just calling a function. The static struct is not "imported" into Objective-C, whatever that might mean.
In any case, the variable someVariable
is singular. There's just one such variable. No matter from where cFunctionModifyingSomeVariable()
is called, it still just works with that one variable. That C function does not know about instances of an Objective-C class or, more generally, anything about its callers, so its behavior can't differ based on that.
Upvotes: 3