-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an example to the FFI guide #19968
Conversation
The `extern "C"` makes this function adhere to the C calling convention, as | ||
discussed above in "[Foreign Calling | ||
Conventions](guide-ffi.html#foreign-calling-conventions)". The `no_mangle` | ||
attribute turns of Rust's name mangling, so that this function can be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/of/off/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😅
ed67534
to
d94c620
Compare
|
||
``` | ||
#[no_mangle] | ||
pub extern "C" fn hello_rust() -> *const u8 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally prefer to drop the "C"
wherever possible as it's the default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh interesting. @aturon do we have any convention here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aturon says no official one, but:
steve@warmachine:~/src/rust$ git grep 'extern {' | wc -l
253
steve@warmachine:~/src/rust$ git grep 'extern "C" {' | wc -l
25
So, seems legit. :)
@steveklabnik ping |
This has now been updated to be on the book, and I fixed the style issue. @alexcrichton r? |
} | ||
``` | ||
|
||
The `extern "C"` makes this function adhere to the C calling convention, as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/"C"//
@alexcrichton both nits fixed |
Add an example to the FFI guide Reviewed-by: alexcrichton
Add an example to the FFI guide Reviewed-by: alexcrichton
Doing this manually as part of #21300 |
This is a little short, but the FFI guide needs a cohesive go-over, and this at least adds the information in the meantime.
It also modernizes the style in a small way, by moving the tilde syntax to the grave syntax.