use Inline C => <<'__EOC__'; void print_iv(SV* input) { SvGETMAGIC(input); printf("Printing integer %"IVdf"\n", SvIV(input)); } __EOC__ print_iv(3);
This fixes three errors in the previous answer:
- You need to call
SvGETMAGIC before accessing the scalar if it is magic (special variable). SvIOK should not be checked. How the number is stored, it does not matter.%d not always suitable for IV . Failure to use the correct template may result in segfault.
source share