3

我的 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 ())

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

4

1 回答 1

2

进行以下更改:

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

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

于 2014-01-05T21:45:34.577 回答