-
Notifications
You must be signed in to change notification settings - Fork 380
Support standard C numeric types #874
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
base: master
Are you sure you want to change the base?
Conversation
This adds direct support for the C integer and float types defined in std::os::raw. Unlike existing cxx-supported integers, these may not be a consistent length on all platforms - but sometimes this is useful to enable direct interoperability with existing APIs.
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, this is great.
However I am slightly hesitant to land this without having #682 because it breaks code like:
#[cxx::bridge]
mod ffi {
extern "C++" {
include!("header.h"); // `using c_int = int;`
type c_int;
}
extern "Rust" {
fn f(v: &CxxVector<c_int>);
}
}
Maybe it would turn out fine for this specific set of names. Let me think about it.
Would you be able to look into whether there is an easy implementation of #682 that would prevent this PR from breaking previously working code?
Yep, I'll take a look. |
Floats are always 32-bit and doubles always 64-bit, so there's no need to duplicate the existing f32 and f64 support.
I added a design sketch to #682 - please take a look. It looks OK, but non-trivial, so unlikely I'll get to it especially soon. Maybe though. |
Status on this? |
Hi, Prior to, or in addition to, this PR landing, is there a way to improve the docs with guidance on how to handle numeric types? Besides this table, I can't find any guidance aside from this terse sentence:
What about This may be something people with c++ backgrounds would know, but in c++ is My background:
My journey: (This part is a longer narrative and hopefully useful to people thinking about improving docs.) I want to write a rust function to parse commandline options and a config file given the Inside the This gives a
Fair enough. Ok, so I remove the But wait, building now works, even though I didn't replace So as it stands, I'm somewhat mystified about the primitive numeric types and which types are in scope within the BTW- if this PR lands, and I could simply use the |
I also frequently see failing code going through partial builds sometimes. there seems to be some minor caching problems with partial builds. Try cargo clean and retry, “c_char” should fail. |
Hello. It looks like this thread's been stale for over a year now, may I know how it's going? |
What is the status is current project? Because of this, |
This adds direct support for the C integer and float types
defined in
std::os::raw
. Unlike existing cxx-supported integers,these may not be a consistent length on all platforms - but sometimes
this is useful to enable direct interoperability with existing
APIs.