3 ms·
> you can very much write aliasing-safe systems code (or even kernel code, for that matter) Yeah, sometimes it's possible. Usually by making a mess of everythi
by matheusmoreira 5y ago
> you can very much write aliasing-safe systems code (or even kernel code, for that matter)
Yeah, sometimes it's possible. Usually by making a mess of everything with unions. If I remember correctly, type punning with unions is still illegal C code but in practice every compiler understands the idiom.
The simple and intuitive solution to many problems is to cast the data to the new pointer and work directly with it. This should always produce correct code no matter what. People think like this and they write code with these assumptions in mind. In practice, nobody really cares too much what the C standard says. What matters is whether the compilers produce the desired code.
- deleted 5y ago[deleted]
- saagarjha 5y agoPinning via unions is legal in C. Casting via a pointer is not and may produce incorrect code.