tech-userlevel archive

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

Re: Return Value of realloc(3)



On Sun, Dec 30, 2012 at 03:20:40AM -0500, Mouse wrote:
 > >> "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?

The latter; it's supposed to forbid the former. This became an issue
with the rise of C++, where it sometimes made sense to create empty
objects and pass them around as tags. This gets weird if the zero-
length objects are allowed to all "appear" at the same address.

Or so I understood it at the time, anyway.

Anyhow, the libc documentation is supposed to document the libc
interface. Documenting properties of the implementation that are not
guaranteed by the interface is not a step forward.

It is equally undesirable, for example, to document how (or whether)
malloc uses sbrk().

-- 
David A. Holland
dholland%netbsd.org@localhost


Home | Main Index | Thread Index | Old Index