Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Recursing in XS?

by syphilis (Canon)
on Apr 19, 2013 at 06:57 UTC ( #1029464=note: print w/ replies, xml ) Need Help??


in reply to Recursing in XS?

Here's an XS file for a module and package My::Mod.
It contains a function named foo() that recursively calls itself until the supplied integer argument has been incremented to 20 (whereupon it returns the value '20').
If the supplied integer argument is >= 20, it returns that value immediately ... and if the supplied integer argument is a *lot* less than 20, then it might take a while to complete.

#include "EXTERN.h" #include "perl.h" #include "XSUB.h" int foo(int x) { if(x >= 20) return x; x++; x = foo(x); } MODULE = My::Mod PACKAGE = My::Mod PROTOTYPES: DISABLE int foo (x) int x
Cheers,
Rob


Comment on Re: Recursing in XS?
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2015-07-28 07:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (252 votes), past polls