-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
size_t should be defined as uint #11447
Comments
You can work around this by casting a use std::libc::{malloc, size_t};
unsafe fn foo() { malloc(10u as size_t); } |
Absolutely, but the ideal solution is to not require any casts. |
Agree it should be uint. |
And likewise ssize_t int. |
Nominating. |
We should check the spec to make sure size_t and uintptr_t are always the same. |
Accepting for P-backcompat-libs |
@brson: They're not necessarily always the same. Although, I think in practice every architecture Rust will target uses the same types for these. Rust assumes they are the same throughout the implementation. |
I no longer think it should be uint since the C spec doesn't define size_t as being pointer sized. |
@brson It also doesn't say it shouldn't be pointer-sized (afaik). It doesn't make much sense for malloc to take a size_t if a size_t isn't pointer-sized. That's the main gripe I've had with its current definition so far. |
@ecl3ctic: Some architectures had segmented memory models, and using different sizes for |
Nominating for closing, per previous discussion: |
We do assume these are the same throughout the API design of the standard library and the language itself. We would need to change indexing to use |
@thestinger can you expand on that? I do not understand how the definition of size_t impacts anything in Rust. |
@thestinger it is not clear to me why the definition of the |
C also doesn't define floating point as having a radix of 2 or even that |
@thestinger okay, reading over your earlier comments I realized that I was misinterpreting your overall message. |
team decided to let |
I agree with leaving it that way FWIW, because I want us to be auto-generating these definitions. :) I just don't want Rust to try supporting a different sized |
`never_loop` catches `loop { panic!() }` * Depends on: rust-lang#11447 This is an outgrowth of rust-lang#11447 which I felt would best be done as a separate PR because it yields significant new results. This uses typecheck results to determine divergence, meaning we can now detect cases like `loop { std::process::abort() }` or `loop { panic!() }`. A downside is that `loop { unimplemented!() }` is also being linted, which is arguably a false positive. I'm not really sure how to check this from HIR though, and it seems best to leave this epicycle for a later PR. changelog: [`never_loop`]: Now lints on `loop { panic!() }` and similar constructs
The C-standard definition of
size_t
states that it must be able to represent the size of any object in bytes. It therefore makes sense forsize_t
to be defined asuint
, to make it equal to the pointer size. Currently (as an example) it's defined asu32
on x86 andu64
on x86-64, but this poses problems with themalloc
family of functions instd::libc::funcs::c95::stdlib
that accept asize_t
, since it is currently invalid to pass them auint
without casting. It makes the most sense to specify the size of a memory allocation with a type of size equal to that of a pointer, so you shouldn't need to do a cast to pass these functions values.The text was updated successfully, but these errors were encountered: