Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^3: Passing integer pointer in XS? (OUTPUT:)

by tye (Sage)
on Jul 18, 2016 at 20:42 UTC ( #1167999=note: print w/replies, xml ) Need Help??


in reply to Re^2: Passing integer pointer in XS? (&)
in thread Passing integer pointer in XS?

So, you'll need to add just a bit more:

int tdSensor(protocol, protocolLen, model, modelLen, id, dataTypes) char * protocol int protocolLen char * model int modelLen int & id int & dataTypes CODE: RETVAL = tdSensor(protocol, protocolLen, model, modelLen, &id, &da +taTypes); OUTPUT: RETVAL id dataTypes

Sorry, it has been many years since I learned this stuff.

- tye        

Replies are listed 'Best First'.
Re^4: Passing integer pointer in XS? (OUTPUT:)
by ikegami (Pope) on Jul 18, 2016 at 21:38 UTC

    Problem: You can't write to protocol or model safely because one of the force functions wasn't used. You might end up changing variables and constants you didn't mean to change. (They might have fixed that in 5.24?)

    use strict; use warnings; use feature qw( say ); use Inline C => <<'__EOS__'; void testing(char* s) { s[0] = 'y'; } __EOS__ my $x = "x"; my $y = $x; say "$x-$y"; testing($y); say "$x-$y";
    x-x y-y <-- Changed both $x and $y
    or
    for (1..2) { my $y = "x"; say $y; testing($y); }
    x y <-- Changed the constant!

    Note: The caller will need to do s/\0.*// for $protocol, $model;

      I suspect that those "char *" arguments are treated such that they could be "const char *" arguments. I also suspect that "\0" characters are not expected. But if I am wrong then, yes, you need to do more work than I did. Thanks.

      - tye        

        And thank you for showing me int &. It's not valid C, but apparently it's valid XS. I did not know that.

Re^4: Passing integer pointer in XS? (OUTPUT:)
by martin67 (Novice) on Jul 18, 2016 at 21:04 UTC
    Thank you!

    This also works! (I got another variant further down in the thread.)

    This was my first question to Perlmonks and I'm impressed by the speed and quality of the answers!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2020-10-27 06:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (256 votes). Check out past polls.

    Notices?