4 ms·
> allocating a few bytes that weren't asked for. FWIW the alignment guarantees of `malloc()` mean it often will have to allocate more than you ask for (before
by DSMan195276 1y ago
> allocating a few bytes that weren't asked for.
FWIW the alignment guarantees of `malloc()` mean it often will have to allocate more than you ask for (before C23 anyway). You can't 'legally' use this space, but `malloc()` also can't repurpose it for other allocations because it's not suitably aligned.
That said I still agree it's a hack compared to just using `malloc(1)` for this purpose, it's well-defined and functionally equivalent if you're looking for a unique address. The fact that you don't know what `malloc(0)` is going to do makes it pretty useless anyway.
- Joker_vD 1y ago> before C23 anyway Did they change "suitably aligned for any object type" to "suitably aligned for any object type with size less than or equal to what was requested" or something like in C23?
- JdeBP 1y agoSee https://news.ycombinator.com/item?id=44390258 https://news.ycombinator.com/item?id=44390258 .