Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
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 exploiting the Monastery: (9)
As of 2014-12-25 01:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (159 votes), past polls