• 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: C functions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C functions


  • Subject: Re: C functions
  • From: Uli Kusterer <email@hidden>
  • Date: Fri, 18 Oct 2013 18:15:03 +0200

On Oct 18, 2013, at 4:48 AM, Shane Stanley <email@hidden> wrote:
> is there any way to build a call to a C function on the fly? I mean something like pass a string to a method, and have it call the function of that name?


 Short: No. Long: Maybe.

 1) You can put a function in a dynamic library and export it, and load that library. If you know its signature, you can then call it.

 2) You can build a look-up table of name -> function pointer mappings inside your application, then look up the function pointer by name and call it. You'd need to know its signature then, too.

 3) You can build a dynamic library that has this function as its main entry point and call that. Essentially a variant of #1. You'll still need to know its signature beforehand then

 4) You can use a library like libffi to call a function pointer (using the methods in #1 through #3 to get one from a name) even without knowing its calling conventions beforehand. As long as you know the signature the moment you're calling it and have the proper values, that'll work (this is what you'd do if you wanted to make e.g. CoreFoundation APIs accessible to a scripting language)

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de


_______________________________________________

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


  • Follow-Ups:
    • Re: C functions
      • From: Shane Stanley <email@hidden>
    • Re: C functions
      • From: Uli Kusterer <email@hidden>
    • Re: C functions
      • From: Jeffrey Oleander <email@hidden>
References: 
 >C functions (From: Shane Stanley <email@hidden>)

  • Prev by Date: Re: C functions
  • Next by Date: Re: C functions
  • Previous by thread: Re: C functions
  • Next by thread: Re: C functions
  • Index(es):
    • Date
    • Thread