Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Extending with C functions - some basic questions

by andal (Hermit)
on Dec 17, 2010 at 11:16 UTC ( [id://877619]=note: print w/replies, xml ) Need Help??


in reply to Re: Extending with C functions - some basic questions
in thread Extending with C functions - some basic questions

3. Can I pass a pointer to a function and have the C library call it

No. See perlcall for how to do it (it comes with several examples).

Well, the answer really is "Yes. See perlcall for how to do it" :)

You can do anything with XS, but you have to provide enough "glue" so that the code provided by your C library cooperates nice with the rest of perl interfaces.

  • Comment on Re^2: Extending with C functions - some basic questions

Replies are listed 'Best First'.
Re^3: Extending with C functions - some basic questions
by Anonyrnous Monk (Hermit) on Dec 17, 2010 at 12:57 UTC

    ...depends on how you interpret the word "pointer" that the OP used.

    If you read it as "C pointer" (as I did), i.e. an address of the entry point of the function in the compiled machine code, then the answer is strictly speaking "no", because Perl alone (without the help of XS modules) doesn't provide any direct way to get at the respective address — which in turn means you can't pass it to the C function. (And even if there was a way, it would not be recommended for normal purposes. Also, Perl functions don't directly correspond to compiled machine code.)

    If, OTOH, you read "pointer" as "Perl reference", then yes, sure you can pass it to the C function and use call_sv() to call it.

    Anyhow, it doesn't really matter whether the answer starts with yes or no, as long as the OP reads the referenced manual, in which case everything will become clear (hopefully :)

      Thanks andal and anonymous. Will read perlcall and come back if I have any questions

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://877619]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-26 00:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found