3 ms·
I'm referring to the definitions of the Rust functions. As far as I know, `#[no_mangle]` disables name-mangling but doesn't change the ABI of a function. That'
by dikaiosune 10y ago
I'm referring to the definitions of the Rust functions.
As far as I know, `#[no_mangle]` disables name-mangling but doesn't change the ABI of a function. That's what `extern "C"` is for in Rust -- to declare a function with the C ABI. You can have a Rust ABI function with an unmangled name (what it looks is done in the post) and you can have a C ABI function in Rust with a mangled name (by using `extern "C"` but not `#[no_mangle]` -- for example for C callbacks).
Based on my limited understanding of C++, `extern "c"` in C++ is equivalent to using both `#[no_mangle]` and `pub extern "C"` in Rust. I would guess that much of the time failing to specify a C ABI would work out fine unless you try to accept or pass non-FFI types (enums, references, etc) but I'm not sure.
It's confusing as hell. There was a thread about the mixed up semantics somewhat recently on the internals forum: https://internals.rust-lang.org/t/no-no-mangle/3973 https://internals.rust-lang.org/t/no-no-mangle/3973 (edit: and also https://internals.rust-lang.org/t/precise-semantics-of-no-mangle/4098 https://internals.rust-lang.org/t/precise-semantics-of-no-ma...).
If you look at the LLVM IR generated from https://is.gd/Hfup3X https://is.gd/Hfup3X you can see that the extern "C" fn differs in that it's given a `nounwind` attribute, among other things.
- wyldfire 10y agoOk, good call. Thanks for the tip btw I think this means I have a bug in my code. ;)
- dikaiosune 10y agoI'm glad it helped! Sorry if it came on strong.