• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Calling a Cocoa library from C
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Calling a Cocoa library from C


  • Subject: Re: Calling a Cocoa library from C
  • From: Jens Alfke <email@hidden>
  • Date: Sat, 12 Nov 2011 13:21:58 -0800

On Nov 12, 2011, at 12:01 PM, Nathan Sims wrote:

> Hmm, if not a global, where would the declaration go? The C function certainly shouldn't return it, so if it is to remain persistent across calls, wouldn't the logical (the only?) place for it be as a global in the library's .m file?

Not necessarily. For example, if your C library already allocates some kind of ‘context’ structure, you could add an ObjcCode* variable to that struct to store the object reference.

I’m just pointing this out because using global variables in a library can create problems for thread-safety and re-entrancy. It’s often considered better design to put the library’s data into some struct/object that can be managed by the caller, so there could be a separate one for each thread or for independent clients.

—Jens_______________________________________________

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

References: 
 >Calling a Cocoa library from C (From: Nathan Sims <email@hidden>)
 >Re: Calling a Cocoa library from C (From: Wim Lewis <email@hidden>)
 >Re: Calling a Cocoa library from C (From: Nathan Sims <email@hidden>)
 >Re: Calling a Cocoa library from C (From: Thomas Davie <email@hidden>)
 >Re: Calling a Cocoa library from C (From: Nathan Sims <email@hidden>)

  • Prev by Date: Re: Calling a Cocoa library from C
  • Next by Date: NSBitmapImageRep and alpha channel
  • Previous by thread: Re: Calling a Cocoa library from C
  • Next by thread: Re: Calling a Cocoa library from C
  • Index(es):
    • Date
    • Thread