Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Hey y'all,

Trying to get the hang of this xs stuff and at a hump I can't seem to get over ...

Modifying a passed parameter.
The goal is to return the Int value and modify the passed arg to true or false (pass or fail on the conversion)

MyLib is a stupid simple string class, strToInt() works correctly, both in the return value as well as modifying the passfail value.
However, It does not show the changes in Perl.

The xs code. (with some printf's)

int MyLib::strToInt(passfail) bool passfail; CODE: if(passfail) { printf("It's true in xs. %i\n", passfail); } else { printf("It's false in xs. %i\n", passfail); } RETVAL = THIS->strToInt(&passfail); if(passfail) { printf("It's true out xs. %i\n", passfail); } else { printf("It's false out xs. %i\n", passfail); } OUTPUT: RETVAL passfail

The Perl calling code.

my $passfail = 0; my $tmp = MyLib->new("12"); my $t = $tmp->strToInt(\$passfail); print "It's $t\n" if $passfail eq 1;

The above code produces the following output:

It's false in xs. 0 It's true out xs. 1
So the xs and C code works

What the blazes am I doing wrong!
Perlxstut makes it look simple ...


fh : )_~

In reply to xs modifying passed value by Festus Hagen

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (3)
    As of 2018-05-25 09:25 GMT
    Find Nodes?
      Voting Booth?