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

FFI tutorial: explicitly document how to define a function callable from C #10489

Closed
pnkfelix opened this issue Nov 14, 2013 · 4 comments
Closed
Labels
A-FFI Area: Foreign function interface (FFI)

Comments

@pnkfelix
Copy link
Member

I believe one is able to define C -> Rust function (Rust code callable from C) like this:

extern "C" fn foo(x: ::std::libc::c_int) -> ::std::libc::c_int { 2 * x }

but the construction above is at best only hinted at in the current tutorial-ffi.md

@pnkfelix
Copy link
Member Author

part of #11755

@steveklabnik
Copy link
Member

@alexcrichton
Copy link
Member

That covers a bit of it, but there's no discussion of #[no_mangle] which is often quite useful.

@thestinger
Copy link
Contributor

It also doesn't mention the necessity to catch failure and either translate it into an error for the C caller or abort if that's not possible. It's undefined behaviour to unwind from Rust into C code.

steveklabnik added a commit to steveklabnik/rust that referenced this issue Jan 16, 2015
flip1995 pushed a commit to flip1995/rust that referenced this issue Mar 24, 2023
New lint: detect unnecessary struct building

Fixes rust-lang#10476.

Running this lint on the top 500 crates produced one hit (in `rust-lang/rust-bindgen`) and [a PR has been submitted there](rust-lang/rust-bindgen#2440).

changelog: [`unnecessary_struct_initialization`]: new lint
flip1995 pushed a commit to flip1995/rust that referenced this issue Apr 6, 2023
…zation-nursery, r=flip1995

Move unnecessary_struct_initialization to nursery

changelog: none, assuming it makes into the same release as rust-lang#10489

Mostly because of rust-lang#10547 but there is also rust-lang#10548
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-FFI Area: Foreign function interface (FFI)
Projects
None yet
Development

No branches or pull requests

4 participants