-
Notifications
You must be signed in to change notification settings - Fork 290
Write a basic "call Rust from C" example #296
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
Conversation
src/ffi.md
Outdated
``` | ||
|
||
The `extern "C"` makes this function adhere to the C calling convention, as discussed above in "[Foreign Calling Conventions]". | ||
The `no_mangle` attribute turns off Rust's name mangling, so that it is easier to link to. |
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.
The `no_mangle` attribute turns off Rust's name mangling, so that it is easier to link to. | |
The `no_mangle` attribute turns off Rust's name mangling, so that it has a well defined symbol to link to. |
I realize you just moved this from below, but the way it is written seems strange to me. With a mangled name, I don't think you'd be able to guess the symbol name at all, which makes linking mostly impossible?
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 moved it because we have the "Callbacks from C code to Rust functions" section below. Applied your suggestion, is it okay with you now?
FWIW, this chapter seems to be getting quite long. At some point it might be worthwhile to consider breaking it up. |
4f56020
to
88b2dbc
Compare
Sorry for the huge delay! I applied your comments.
Sounds good, I'll do it on another PR not to make this PR large. |
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.
Thanks!
Update books ## nomicon 3 commits in 2d66852a27c5d0ec50ae021820d1de22caa2b1bd..358e6a61d5f4f0496d0a81e70cdcd25d05307342 2021-10-07 19:00:37 +0900 to 2021-10-20 11:23:12 -0700 - Write a basic "call Rust from C" example (rust-lang/nomicon#296) - Clarify the Safe vs. Unsafe Rust relationship (rust-lang/nomicon#294) - Fix typo with respect to dangling pointer (rust-lang/nomicon#319) ## book 8 commits in eb1282ec444db94055fa9531b6f3f803e86bb382..fd9299792852c9a368cb236748781852f75cdac6 2021-09-16 21:17:09 -0400 to 2021-10-22 21:59:46 -0400 - Reword description to emphasize what return does in a match arm - Correct backwards wording describing From impls. Fixes rust-lang/book#2829 - Remove multiple negatives, add examples. Fixes rust-lang/book#2833 - Fix capitalization in sidebar. Fixes rust-lang/book#2860 - fix quotes - comments from nostarch and responses for chapter 2 - (rust-lang/book#2906) - Merge pull request rust-lang/book#2892 from Enrico2/patch-1 ## rust-by-example 1 commits in 9a60624fcad0140826c44389571dc622917cd632..27f1ff5e440ef78828b68ab882b98e1b10d9af32 2021-10-04 08:13:53 -0300 to 2021-10-13 08:04:40 -0300 - Added example of `impl Trait` as an argument (rust-lang/rust-by-example#1468) ## embedded-book 1 commits in 270fccd339e5972d9c900e788f197e81a0bcd956..51739471276b1776dea27cf562b974ef07e24685 2021-10-06 16:28:48 +0000 to 2021-10-17 16:48:42 +0000 - Fix typo in 'The Borrow Checker' (rust-embedded/book#305)
Fix #138
I'm not sure if this is the simplest way but should make it easy to understand.