News for hackers. Stuff that matters.
Re:Implementing Hash Tables in C by simias on Saturday October 16, 2021 @04:21PM (#28891129)
It's definitely rife with footguns but you can very much write aliasing-safe systems code (or even kernel code, for that matter). Or at the very least you should strive to contain the alias-infringing code in well delimited sections of the source code that are built with special flags for instance.

If optimizations break code due to aliasing violations I would really recommend fixing the code, not turning the optimizations off!

Also if anything C's aliasing is less strict than Fortran by default, hence the later introduction of "restrict" to allow further optimizations.

Re:Implementing Hash Tables in C by matheusmoreira on Saturday October 16, 2021 @05:12PM (#28891568)
> 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.

Re:Implementing Hash Tables in C by saagarjha on Saturday October 16, 2021 @11:56PM (#28893822)
Pinning via unions is legal in C. Casting via a pointer is not and may produce incorrect code.