![](/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.