【发布时间】:2018-10-09 16:32:48
【问题描述】:
来自this conversation in the Perl 6 IRC channel 和Martin Barth 发布的一个问题,我正在尝试使用用于该目的的Perl6 NativeCall 接口reproduce this C code。这是我尝试过的:
use NativeCall;
my uint32 $num = .new;
my num32 $float = .new: Num(1.0);
sub memcpy(num32 $float, uint32 $num, int32 $size) is native('Str') { * };
memcpy($float,$num,4);
say $num;
这会产生一个错误:
This type cannot unbox to a native integer: P6opaque, Any
我的解释是,你已经将它声明为一个整数,我不能把它变成原始内存,以便它可以从这里复制到那里。
这只是回答 Martin Barth 提出的更一般性问题的一种可能方式:如何将原始字节转换为浮点数。也许还有其他方法可以做到这一点,但无论如何我都很想知道如何将 C 程序转换为 NativeCall 等价物。
更新:与此同时,here's the original question this other post tries to be a solution for。
【问题讨论】:
标签: raku data-representation nativecall