←back to thread

55 points ingve | 1 comments | | HN request time: 0.279s | source
Show context
AaronDinesh ◴[] No.44389347[source]
Why should it be allowed to return a valid pointers anyways? Surely it should always return NULL?
replies(5): >>44389371 #>>44389461 #>>44389531 #>>44390081 #>>44392719 #
1. bobmcnamara ◴[] No.44392719[source]
> Why should it be allowed to return a valid pointers anyways?

malloc(0) is allowed to return non-NULL because the standard decrees it.

One way of thinking is that all mallocated pointers must always be freed exactly once. Then you're portable.