Open
Description
Feature gate: #![feature(c_size_t)]
.
This is a tracking issue for std::os::raw::{c_size_t, c_ssize_t}
, which are guaranteed to be the same size as the underlying C size_t
and ssize_t
types from stddef.h
.
Currently, on all targets, this is equivalent to usize
and isize
, however Rust has historically gone somewhat out of its way to avoid promising this. There are some targets with vaguely-planned support where this is not true (W65, used for SNES homebrew, for example)
Further reading here is available:
- https://rust-lang.zulipchat.com/#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/.60usize.60.20vs.20.60size_t.60
- https://internals.rust-lang.org/t/abi-discussion-for-w65/15092
- size_t vs usize rust-bindgen#1671
And probably more.
Public API
// std::os::raw
pub type c_size_t = usize;
pub type c_ssize_t = isize;
Steps / History
- Implementation: Add
c_size_t
andc_ssize_t
tostd::os::raw
. #88340 - Final comment period (FCP)
- Stabilization PR
Unresolved Questions
- Do we want to instead guarantee
usize
andsize_t
are the same? See https://internals.rust-lang.org/t/pre-rfc-usize-is-not-size-t/15369 - Should this instead live in
libcore
somehow, given that probablylibstd
may never support platforms where this is not true. (This may not be true, since I imagine CHERI will support libstd) - Do we need both the signed and unsigned version, given that
size_t
is more common in function signatures. - ...