Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Inline::C - Why are my params in the stack?

by stevieb (Abbot)
on Dec 06, 2018 at 21:01 UTC ( #1226857=note: print w/replies, xml ) Need Help??


in reply to Inline::C - Why are my params in the stack?

Ahhh, bloody heck. One minute after posting the question, Rubber Duck Debugging rescues me again.

In Inline::C, it explains the Inline_Stack_Reset call:

use warnings; use strict; use Inline 'C'; my @random_numbers = getRand(1, 1000, 100); print "$_\n" for @random_numbers; __END__ __C__ #include <stdlib.h> void getRand (int start, int end, int iterations){ time_t t; srand((unsigned) time(&t)); inline_stack_vars; inline_stack_reset; // <-- HERE int i; for (i = 0; i < iterations; i++){ int randomNum = rand() % (end - start); inline_stack_push(sv_2mortal(newSViv(randomNum))); } inline_stack_done; }

That resolves the problem. Effectively, it resets the stack before appending to it.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (14)
As of 2019-03-21 11:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How do you Carpe diem?





    Results (108 votes). Check out past polls.

    Notices?