gpt4 book ai didi

haskell - 使用 c2hs 编码 void*

转载 作者:行者123 更新时间:2023-12-02 01:54:39 27 4
gpt4 key购买 nike

我的 C 函数如下所示:

void *c_shm_create(char*, int);

我的 .chs 文件如下所示:

{-# LANGUAGE ForeignFunctionInterface #-}

module System.Shm.Internal.Bindings
( c_shmCreate
)
where
#include "hs_shm.h"
import C2HS

{#fun unsafe c_shm_create as c_shmCreate
{ `String'
, `Int' } -> `Ptr ()' #}

这是我得到的错误:

src\System\Shm\Internal\Bindings.chs:12: (column 18) [ERROR]  >>> Missing "out" marshaller!
There is no default marshaller for this combination of Haskell and C type:
Haskell type: Ptr ()
C type : (Ptr ())

我在 c2hs 文档中找不到任何关于 void pointer (Ptr ()) 的提及。我该如何编码这个?

最佳答案

进行以下更改:

{#fun c_shm_create as c_shmCreate { `String' , `Int' } -> `Ptr ()' id #}

我不确定这是错误还是故意的。 Haskell 数据类型和 C 结构可能被认为是“相等的”,因为它们表示相同的数据,但表示不相同(结构是堆上的纯字节,而数据类型是指针等)所以你需要一个编码(marshal)处理不仅仅是 id 的函数。

关于haskell - 使用 c2hs 编码 void*,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20931099/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com