![](/img/trans.png)
[英]What's the difference between extern fn and extern “C” fn in Rust?
[英]type OnProduce = extern "C" fn is not FFI safe
pub type OnProduce = extern "C" fn(*mut ZLMedia, *const u8, size_t);
extern "C" {
pub fn zlmedia_set_on_produce(zl_media: *mut ZLInstance, on_produce: OnProduce);
}
我得到:
|
23 | pub fn zlmedia_set_on_produce(zl_media: *mut ZLInstance, on_produce: OnProduce);
| ^^^^^^^^^ not FFI-safe
|
= help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
= note: this struct has unspecified layout
但不能为类型添加#[repr(C)]
,只能为结构添加。 如您所见, OnProduce
是一个extern "C"
函数。 我以为它已经是 FFI 安全的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.