• 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: Passing Obj-C method as callback to C function
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >Re: Passing Obj-C method as callback to C function (From: Bill Cheeseman <email@hidden>)

  • Prev by Date: Re: Passing Obj-C method as callback to C function
  • Next by Date: Re: Generic application icon
  • Previous by thread: Re: Blocks in Obj-C (was: Passing Obj-C method as callback to C function)
  • Next by thread: Omni Framework Hell Again
  • Index(es):
    • Date
    • Thread