This is getting a bit off-topic, but...

>--- Forwarded mail from [EMAIL PROTECTED]

>[EMAIL PROTECTED] on 05/02/2000 03:13:34 PM

>>Although looking at the xmalloc call, I don't know if it's such
>>a good thing for it to take a 0 length request and turn it into
>>a 1 byte request.  Why would we need to ask for a 0 length portion
>>of memory?

>I was looking at that, too.  I tend to feel that 0-byte allocations should be
>allowed (returning NULL) and, if systems' frees don't handle NULL properly,
>there should be an xfree() that'll do so.

I can see the occasional need to allocate a unique pointer that points to
nowhere but is distinguishable from any other pointer, even NULL.  Having a
malloc-like function that does this (allocate a block of memory at least 0
bytes long and return a pointer to it) is useful, and if it's implemented as
a wrapper that increments a 0 size then so be it.

This practice is typically used when there's a distinction to be made
between an "unset" value and a "set but unspecified" value.  An example
of such data in CVS are commit comments:  Comments can be prompted for if
the string is unset.  Or, an empty comment can be stored (without a prompt)
if the string is set but unspecified.

This is a somewhat contrived example because for strings this distinction
is made by using a NULL pointer for an unset value, and a pointer to an
empty string for a set but unspecified value.  But for structures the
distinction is a little harder to implement, and special pointers are
one economical way to do it.  Timestamps are another type of data where
this distinction might be important, in many applications.

>--- End of forwarded message from [EMAIL PROTECTED]

Reply via email to