tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Return Value of realloc(3)



>> "If size is 0, either NULL or a unique pointer that can be
>> successfully passed to free(3) is returned."

I don't like this language.  Does "unique" here mean that there is only
one such pointer (returned by all such calls), or does it mean that it
is distinct from all other non-nil pointers returned by malloc-family
functions?

> I agree.  And we might as well also document what happens when zero
> is passed to malloc or calloc.

We could, but...

> If we also document which of the two behaviours is used by NetBSD,
> then we should be careful not to encourage callers to [rely] on that
> implementation decision, because it may change in the future while
> remaining compatible with relevant standards.

...I would prefer to document it only to the extent that it's a pointer
value which must not be dereferenced but can be passed to free, and can
be cast to a pointer to any object type and still remain a valid
argument to free().  (In particular, I would not promise whether this
pointer is nil or not.  I also would not promise that it can be cast to
an object type and back without change, only that the result can still
safely be free()d.)

I also wouldn't use the term "NULL" anywhere in the documentation, but
that's a completely separate issue.

/~\ The ASCII                             Mouse
\ / Ribbon Campaign
 X  Against HTML                mouse%rodents-montreal.org@localhost
/ \ Email!           7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B


Home | Main Index | Thread Index | Old Index