简体   繁体   English

Rust中extern fn和extern“C”fn有什么区别?

[英]What's the difference between extern fn and extern “C” fn in Rust?

I've tried reading various github issues trying to track down what the difference is and just ended up confused. 我已经尝试阅读各种github问题,试图找出差异是什么,只是最终混淆了。

#[no_mangle]
pub extern fn foo() {
   ...
}

vs.

#[no_mangle]
pub extern "C" fn foo() {
   ...
}

There is no difference because, as the reference says: 没有区别,因为参考文献说:

By default external blocks assume that the library they are calling uses the standard C ABI on the specific platform. 默认情况下,外部块假定它们调用的库使用特定平台上的标准C ABI。

extern "C" -- This is the same as extern fn foo(); extern "C" - 这与extern fn foo(); whatever the default your C compiler supports. 无论C编译器支持哪种默认值。

An issue was created to always require explicitly stating extern "C" but the RFC has been refused . 创建了一个问题 ,始终要求明确声明extern "C"RFC已被拒绝

There is an issue in fmt-rfcs about "should we format extern "C" fn as that or extern fn ?". fmt-rfcs中存在一个问题: “我们应该格式化extern "C" fn as that还是extern fn ?”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM