Re: Accessing Cocoa instance variables from C functions
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