Re: Static variables reset inside CFPlugin code
Re: Static variables reset inside CFPlugin code
- Subject: Re: Static variables reset inside CFPlugin code
- From: Jens Alfke <email@hidden>
- Date: Sun, 01 Jan 2012 12:42:33 -0800
On Dec 29, 2011, at 12:11 PM, Grandinetti Philip wrote:
> I'm loading and creating a CFplugin using Core Foundation and running into a strange behavior where all the static variables defined throughout my code get reset to their initialization values when running code inside plugin.
If you have two binaries — an application and a plugin — then each of those has independent global/static variables, even if those variables are declared in the same source files. The scope of globals is basically defined by the linker, and you've linked two independent binaries that have no magic connection to each other.
If you want the two to share a variable, you'll need to:
(a) define it in the plugin code, not the app
(b) declare it as global not static, so it's visible outside that compilation unit
(c) tell the linker to export that global from the plugin, e.g. by using an export file
(d) make the app link against the plugin so it can access the variable
—Jens
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