Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如您所知,对于identC 中的任何标识符,您都可以编写&ident以获取指向 的内存位置(指针)ident,而不管该位置是在堆上还是在堆栈上。在使用 C 类型时,访问此功能通常很有帮助。
ident
&ident
FFI 中的 Haskell 中是否有等效的操作?
如果您有一个要导入 Haskell 的 C 标识符,您可以通过FFI 声明中的“&”语法将其转换为指向该地址的指针,如下所示:
foreign import ccall "&" bar :: Ptr CInt
通常这是很少见的事情,因为您导入的几乎所有内容都已经是一个指针。
Haskell 值本身也可以使用稳定指针转换为指针,以确保它们不受垃圾收集器的影响。