On interoperability between Rust and OCaml

I don’t have a problem with strict aliasing and I don’t remember a time when it wasn’t in the C standard. Quite possibly it wasn’t in K&R, I don’t know. The rules are pretty straightforward - don’t dereference a pointer to a particular type unless an object of that type is actually at the address in question, or you are dereferencing a pointer to char/unsigned char/signed char (signed char permitted in C, not in C++). Or in other words, don’t use pointers for type punning except at the byte level. But if you don’t like it, all compilers I know of have a flag to turn strict aliasing off.

What I was objecting to is breakage and instability. In the context of pointer dereferencing in particular I was complaining about std::launder. More generally I was complaining about the disgraceful state of affairs reported in P0593R6: Implicit creation of objects for low-level object manipulation.

Placement new is necessary for types which have constructors which actually do something. I don’t think I would describe it as a hack, but the fact that array placement new is broken is also disgraceful. To require trivial types to be constructed this way where uninitialized memory is in use, and so break the long standing practice of using assignment or memcpy to do so, is in my view unaccepable.

I suspect that is enough about C and C++.

1 Like