Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

steveklabnik
Copy link
Member

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.

@steveklabnik steveklabnik changed the title Gh10489 Add an example to the FFI guide Dec 18, 2014
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/of/off/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😅


```
#[no_mangle]
pub extern "C" fn hello_rust() -> *const u8 {
Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member Author

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. :)

@emberian
Copy link
Member

emberian commented Jan 5, 2015

@steveklabnik ping

@steveklabnik
Copy link
Member Author

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/"C"//

@steveklabnik
Copy link
Member Author

@alexcrichton both nits fixed

bors added a commit that referenced this pull request Jan 17, 2015
Add an example to the FFI guide

Reviewed-by: alexcrichton
bors added a commit that referenced this pull request Jan 17, 2015
Add an example to the FFI guide

Reviewed-by: alexcrichton
@steveklabnik
Copy link
Member Author

Doing this manually as part of #21300

@steveklabnik steveklabnik deleted the gh10489 branch October 25, 2017 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants