Problems:
Your code won't always compile. PPCODE cannot start with variable declarations as it can be preceded by non-declarations.
should bePPCODE: int i; f();
orPREINIT: int i; PPCODE: f();
PPCODE: { int i; f(); }
Your snippets don't handle magical variables (e.g. $1, %ENV) except sometimes by chance. e.g.
say lengths1(substr("abc", 0, 1)); # 0
lengths1 uses SvLEN when it should be usingSvCUR. e.g.
say lengths1("abc"); # 16
Your snippets suffer from The Unicode bug. e.g. After fixing the above problems,
$_="\x{A0}"; say lengths1($_), "=", length($_); # 1=1 $_="\x{A0}\x{2660}"; chop; say lengths1($_), "=", length($_); # 2=1
lengths1 uses type-based polymorphism —something which should be avoided in Perl— and does it "poorly". e.g. After fixing the above problems,
say lengths1(456), "=", length(456); # 0=3
In reply to Re: Yet Another XS Tutorial
by ikegami
in thread Yet Another XS Tutorial
by cdybedahl
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |