3 ms·
> However, if the type is Copy and all the bytes are zeros, then you know it can be calloc That's not as easy to check as one would think since Copy types can
by the8472 5y ago
> However, if the type is Copy and all the bytes are zeros, then you know it can be calloc
That's not as easy to check as one would think since Copy types can still contain uninitialized bytes.
- PoignardAzur 5y agoYeah, but in the common case all the uninitialized bytes are in the padding at the end of the struct (since Rust can re-arrange fields). Especially in a case like in the article, where the type is very small (one byte), and the obstacle is that the author is using a newtype.
- the8472 5y agoKnowing that they usually are at the end doesn't help since you still need to write a general runtime check that expresses "are all the bits for this type zero or uninit". Afaik currently there is no way to do this without causing UB. This would need some new intrinsic.