Hacker News new | ask | show | jobs
by averagedev 1594 days ago
Interesting. I don't code in C for a living, and I wasn't familiar with strict aliasing -- thanks for sharing your thoughts.

> Can't do that either I'm afraid for much the same reason, need to memcpy over the memory and trust the compiler to elide said copy

Would this apply even to mmap-ed memory? Especially for the bit you're quoting, I guess it can be fixed with a union (or even by using the same struct for both purposes). But since the TAlloc_malloc function returns a pointer to void *, to a location in memory that hasn't been used for any other purposes, perhaps this isn't a violation?

On another note, I was playing around a bit with strict aliasing rules, and oddly enough, the compiler that ships with Monterey (ARM mac) shows no warnings even for code that violates the rules blatantly. Same code threw a warning with GCC (I used an online compiler).

The memory allocator I wrote doesn't throw any warnings using GCC either, but I guess that doesn't mean much.