Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re^2: xs modifying passed value

by bulk88 (Priest)
on Nov 18, 2012 at 02:03 UTC ( #1004366=note: print w/ replies, xml ) Need Help??

in reply to Re: xs modifying passed value
in thread xs modifying passed value

Considered having the return of MyLib::strToInt be the bool, and the param be the int? Usually subs/funcs return true false, and details of the operation are inplace updates/ pass by reference/ $_[0] = "hello";/*status = 1;/. Or the author of C++ method strToInt did it that way and thats the way you will remember it in Perl? You could also return 2 elements "($truefalse, $theint) = $instance->strToInt();", and have MyLib::strToInt method take only one param (THIS scalar). If the caller in perl doesn't want the int, they dont need to collect it in list context.

edit: With XS/C/Perl internals, the biggest XSUB debugging tool is looking at the .c code. Try posting that. For C code, you should learn how to create post C processor code, then run it through a code formatter. A 7 character named macro taking 1 param, barely or terribly documented, can expand to a screenful of code after 2-5 layers of macros are expanded. To understand why it failed, looking at the post preprocessor output it the only way. Also compile with optimize=debug and symbols, as you said already, you have a C debugger, so thats correct. Also instead of returning 1 bool, or a list, consider returning a hashref, a hashref is probably overkill for this function.

Comment on Re^2: xs modifying passed value
Replies are listed 'Best First'.
Re^3: xs modifying passed value
by bulk88 (Priest) on Nov 18, 2012 at 07:43 UTC
    Some people for param lists do,
    my %localdog; if(@_ == 2 && ref($_[1]) eq 'HASH') { #named params my $hvref = $_[1]; $localdog{name} = $hvref->{name}; $localdog{color} = $hvref->{color}; } else{ $localdog{name} = $_[1]; $localdog{color} = $_[2]; }

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2015-11-30 00:21 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (754 votes), past polls