-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Empty structs should not need #[repr(C)] #18686
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
Comments
The explicit |
Regardless of the representation of the struct on the rust side, it should not break C code that requires a struct with no fields, since it won't be accessing any of those fields. Even when passing one of these things by-value to C, caller cleans up the stack with cdecl, so it should be fine. And in the more frequent case of getting a |
struct X {
};
struct Y {
struct X x;
int i;
}; |
After more investigation, empty structs are not valid C99. Therefore, it seems silly to mark it as |
Irrelevant as long as GCC allows them. |
If it's not valid C, I see (heh) no reason for rust to support it with |
Meanwhile outside the ivory tower we also want to interact with C code that doesn't only use ISO C features (correctly.) Think: 99% of all C code. |
At the risk of entering an argument I may not understand fully... The 'ivory tower' counter-argument here given by mahkoh seems to be placing GCC in an ivory tower of its own. If the standard doesn't support empty structs, why should the 'standard' (reference?) for Rust condone something non-standard? Why not leave that to implementation defined behavior, in the same way that anything done in the C stdlib that may be IB is automatically IB for Rust linking to the C stdlib? I'unno, transitive property of implementation-defined-ness, or something. |
@cgaebel When I implemented this feature, I struggled a bit with what to do about empty structs. I ended up going with this because I think it is annoying and grating to add a field to a struct and suddenly need |
I like the idea of special-casing pointer-to-an-empty-struct. |
I'm pulling a massive triage effort to get us ready for 1.0. As part of this, I'm moving stuff that's wishlist-like to the RFCs repo, as that's where major new things should get discussed/prioritized. This issue has been moved to the RFCs repo: rust-lang/rfcs#750 |
In a lot of FFI code, I see patterns like:
where
X
is used as an opaque "black-box" object. With rust today,X
needs a#[repr(C)]
. That's not really necessary, and caused a bunch of noisy warnings when updating servo's rust version.Can someone mark this bug as easy so a beginner can use it to get started?
The text was updated successfully, but these errors were encountered: