Is downgraded by @ptrCast pointer safe to read via original pointer?

This is undefined behaviour (in C as well), due to aliasing rules. A compiler is free to assume that the usize and the u32 simply do not reside in the same memory and optimize using that assumption, so it’s not even guaranteed to behave correctly on little endian systems.

In other words, don’t do 2. Create a temporary. Unless you’re on a super hot path, the performance difference is negligible.

Side note: big endian systems are basically non-existent nowadays.

EDIT: wording
EDIT2: I was wrong, see this thread

1 Like