• 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: Accessing Cocoa instance variables from C functions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Accessing Cocoa instance variables from C functions


  • Subject: Re: Accessing Cocoa instance variables from C functions
  • From: William Bumgarner <email@hidden>
  • Date: Mon, 24 Apr 2006 10:51:27 -0700

On Apr 24, 2006, at 9:43 AM, Ondra Cada wrote:
It somewhat depends though -- since the implementation is ObjC- based anyway, it might be better to publish the fact (and make the compiler check for typos etc.) by declaring the argument an id, or, better, WhateverClass*.

I would even argue this is much more often case than those when hiding an object under a void* is beneficial :)

Depends entirely on the portability requirement. The original poster indicated that his library is written in straight C. So, unless he wants to "taint" his pure C by introducing ObjCisms, he may have to use (void*).


Personally, I always use a void* in such a case. From the library side of the equation, it makes it adamantly clear that the data is to be treated as an opaque type, never to be interrogated or modified. That is has to be cast back to the specific class* in the callback also makes it absolutely clear that the library has no clue about the type -- it is up to the developer to guarantee correctness. A simple assert() w/-isKindOfClass: makes it as solid as compile time type checking.

b.bum

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Accessing Cocoa instance variables from C functions (From: Damien Sorresso <email@hidden>)
 >Re: Accessing Cocoa instance variables from C functions (From: William Bumgarner <email@hidden>)
 >Re: Accessing Cocoa instance variables from C functions (From: Ondra Cada <email@hidden>)

  • Prev by Date: Core-Data, can you issue an NSrequest from awakefrominsert
  • Next by Date: OT cocoa groups in NYC
  • Previous by thread: Re: Accessing Cocoa instance variables from C functions
  • Next by thread: Re: Accessing Cocoa instance variables from C functions
  • Index(es):
    • Date
    • Thread