upvote
> Take the address and deref afterwards, and it's exactly the same.

It is significantly worse to take address and deref afterwards.

You have to do something like:

@as(const u32, @ptrCast(&x)).

instead of just

@bitCast(x)

> Yes, and this is one reason @bitCast was changed to have different semantics that are not trivially achieved with @ptrCast.

This makes sense except breaking existing code that properly handled endianness by doing a conditional @byteSwap. And what you end up with is a more complicated intrinsic compared to something that reinterprets values with same layout size

reply
> This makes sense except breaking existing code

Before Zig hits 1.0, users should expect language changes. Has anyone claimed otherwise?

If you need the old thing often enough, you can write a wrapper for it. It's a trivial one-liner, as you've shown.

reply