Hein Ragas writes:
>   In example 3 of the perlxstut page, the "round" function, it is shown
> that a constant can not be changed. That's fair enough -- but how can I
> return a "fresh" value back to the calling Perl program? How would the code
> of example 3 have to be modified to be able to do "$i = Mytest::round(4.5)"
> in the test-program?
>   I've looked around for this, but all I could find is the OUTPUT-keyword,
> which does exactly the opposite.

  int
  round(n)
    double n
  CODE:
    RETVAL = n+0.5;
  OUTPUT:
    RETVAL

Here's the relevant slide from the XS section of our advanced class.

Cheers;
Nat

=Return values

* If your function returns a single value, use RETVAL:

  int
  is_odd(num)
    int num
    CODE:
      RETVAL = num % 2;
    OUTPUT:
      RETVAL

* Mark changed parameters in OUTPUT section:

  void
  triple(num)
    int num
    CODE:
      num *= 3;
    OUTPUT:
      num

Reply via email to