logoalt Hacker News

o11cyesterday at 5:17 PM3 repliesview on HN

Noncompliant, since `malloc(0)` is specified to return a unique pointer if it's not `NULL`.

On most platforms an implementation could just return adjacent addresses from the top half of the address space. On 32-bit platforms it doesn't take long to run out of such address space however, and you don't want to waste the space for a bitmap allocator. I suppose you could just use a counter for each 64K region or something, so you can reuse it if the right number of elements has been freed ...


Replies

j1elotoday at 9:02 AM

Oh but no worries with compliance, it always returned a newly created -1, never repeating the same one!

show 1 reply
bobmcnamarayesterday at 5:41 PM

> Noncompliant, since `malloc(0)` is specified to return a unique pointer if it's not `NULL`.

I know I've seen that somewhere, but may I ask what standard you're referring to?

If I recall correctly, this was an archaic stackless microcontroller. The heap support was mostly a marketing claim.

show 3 replies
LPisGoodyesterday at 5:38 PM

Noncompliant, but what could this reasonably impact?

show 2 replies