开发者

Should be there newSVuv instead newSVnv in perlxstut?

开发者 https://www.devze.com 2023-01-18 03:53 出处:网络
I\'m just going through perlxstut and I found there newSVnv in EXAMPLE 5 and EXAMPLE 6 but I think that newSVu开发者_高级运维v should be more appropriate. Curiously newSVnv works too. What\'s going on

I'm just going through perlxstut and I found there newSVnv in EXAMPLE 5 and EXAMPLE 6 but I think that newSVu开发者_高级运维v should be more appropriate. Curiously newSVnv works too. What's going on?


I think it uses NVs (Perl's equivalent of a C double) instead of UVs (normally an unsigned int), because (depending on OS and compilation options), some of the values in a struct statfs might be 64-bit even though Perl is using 32-bit ints. newSVnv works because the C compiler knows how to cast any integer type to a double.

You should be able to replace newSVnv with newSVuv for any member of statfs that will fit in a UV, and have it work just fine. Perl converts between its numeric types automatically as needed.

0

精彩评论

暂无评论...
验证码 换一张
取 消