In reference to @Gankra’s tweet: Currently, the ABI of Rust char
is not documented.
What steps are needed in order to document that Rust char
is ABI-compatible with C char32_t
(for values that are valid for Rust’s char
)?
This should be pretty non-controversial considering that:
- Rust
char
transmutes to and fromu32
indicating that it has to have the same representation asu32
. -
C11 and C17 define
char32_t
as the same type asuint_least32_t
, sochar32_t
clearly has unsigned behavior when passed in registers on 64-bit platforms. -
C++ defines
char32_t
is a distinct type that has the same size, signedness and alignment asuint_least32_t
. -
uint_least_t
can have a width other than 32 bits only if the C implementation doesn’t provide 32-bit-wide integers. Rust is already incompatible with such (theoretical AFAIK) C implementations. Therefore, in C implementations that Rust is compatible with,uint_least32_t
isuint32_t
. - Rust
u32
is ABI-compatible withuint32_t
.