Hacker News new | ask | show | jobs
by nybble41 2322 days ago
If you're lucky enough to be using C11 or C18, sure. There are no alignment keywords in C99. However, that still leaves the aliasing issue, and the fact that objects allocated with malloc() are defined not to overlap with any other object.
1 comments

well you also need another static block for the allocation bitmap or whatever structure you're going to use. How would the pointers that you're generated be aliased if they're unique according to your free map.
They're aliased with the array that you allocated them from. The compiler is free to assume that elements in an array with a declared type of uint8_t won't be accessed via any other type of lvalue (other than another character type). Doing so is undefined behavior, which means there are no guarantees about how any part of the program behaves before or after such an access. In many cases you can get away with it, of course, but a strictly conforming C program can't rely on that.