Il 19/03/2014 16:56, Markus Armbruster ha scritto:
> Given the results, okay to
> use the limited model where realloc never frees and malloc(0) returns
> non-NULL?
I'd describe realloc() as "always frees the old block, returns a new
block, which is never null". We might mean the same.
Yes, that's what I would do too, but it misses an important difference
between malloc() and realloc().
"If size is 0, then malloc() returns either NULL, or a unique pointer
value that can later be successfully passed to free()". Instead, for
realloc, "if size is equal to zero, and ptr is not NULL, then the call
is equivalent to free(ptr)" and presumably must return NULL.
So I'm doubly cheating by giving realloc(foo, 0) free+malloc semantics
instead of free.
BTW, this means that the handy "malloc(0) really means malloc(1)"
semantics are inconsistent because you cannot implement realloc(foo, 0)
that way.
Paolo
Go ahead with the lying^Wlimited model, with a big, fat comment
explaining our reasons.