Re: Passing Obj-C method as callback to C function
Re: Passing Obj-C method as callback to C function
- Subject: Re: Passing Obj-C method as callback to C function
- From: "Alastair J.Houghton" <email@hidden>
- Date: Wed, 29 Oct 2003 09:19:32 +0000
On Tuesday, October 28, 2003, at 08:12 pm, Bill Cheeseman wrote:
on 03-10-28 9:58 AM, email@hidden at email@hidden wrote:
Is it possible to have the callback in the object itself.
Yes. In addition to the option to put it in the @implementation part at
large, there is often an advantage to embedding it inside the
Objective-C
method that triggers the callback. I believe this is covered in the
gcc3
document in DeveloperTools under "Nested Functions," where it is
explained
that a function can be defined at the beginning of any block within an
Objective-C method. Code examples can be found by searching the mamasam
archive for "embed function in method," if I recall correctly. An
advantage
of doing this is that "self" is available to the function without
having to
pass it in as a void* parameter.
I'd quite forgotten that GCC had the nested functions extension. The
only slight caveat is that nested functions do come with a small
performance penalty because of the way they work, so if the callback is
triggered a lot, you may be better-off with an ordinary function.
Kind regards,
Alastair.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.