Re: ld: duplicate symbol
Re: ld: duplicate symbol
- Subject: Re: ld: duplicate symbol
- From: Bill Bumgarner <email@hidden>
- Date: Tue, 30 Sep 2008 13:05:39 -0700
On Sep 30, 2008, at 11:21 AM, Claus Atzenbeck wrote:
On Tue, 30 Sep 2008, Nick Zitzmann wrote:
How have you declared CAPersonSwitchKey in the header file?
int CAPersonSwitchKey = 0;
Making this static solved the problem.
Solved which problem? Making your code compile or making it work?
Declaring CAPersonSwitchKey as 'static' in every source file is, at
the least, a small waste of memory. In the worst case, it won't do
what you want -- if you change CAPersonSwitchKey in a code path in one
source file, the other source files that declare the same static will
not see the new value.
Consider:
main.m:
static int bobO = 42;
int main (int argc, const char * argv[]) {
printf("bobO: %d\n", bobO);
doFred();
bobO = 43;
printf("bobO: %d\n", bobO);
doFred();
return 0;
}
fred.h:
extern void doFred();
fred.c:
static int bobO = 42;
extern void doFred()
{
printf("fred: %d\n", bobO);
}
When run, this spews:
bobO: 42
fred: 42
bobO: 43
fred: 42
b.bum
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden