On Thu, 06 Mar 2008 19:31:30 +0100, Joachim Schmitz wrote:
> Harald van D?k wrote:
>> On Thu, 06 Mar 2008 18:03:02 +0000, Walter Roberson wrote:
>>> In article
>>> <cb101878-66a6-4c38-8bc4-2d1b70b69e19@[EMAIL PROTECTED]
>,
>>> Francois Grieu <fgrieu@[EMAIL PROTECTED]
> wrote:
>>>> When running the following code under MinGW, I get realloc(p,0)
>>>> returned NULL
>>>> Is that a non-conformance?
>>>
>>> No, it is conformance, and returning non-NULL would be
>>> non-conformance.
>>>
>>> [C89 citation snipped]
>>
>> While you're not at all wrong, please keep in mind that this is one of
>> the areas in which C99 differs from the previous standard. In C99, it's
>> unspecified whether realloc(p, 0) returns a null pointer, but if it
>> returns a null pointer, then p is *not* freed.
> I don't read it mlike this
>
> The realloc function returns a pointer to the new object (which may have
> the same
> value as a pointer to the old object), or a null pointer if the new
> object could not be
> allocated.
7.20.3p1 applies to all allocation functions.
"If the size of the space requested is zero, the behavior is
implementation-defined: either a null pointer is returned, or the
behavior is as if the size were some nonzero value, except that the
returned pointer shall not be used to access an object."
This allows realloc(p, 0) to unconditionally fail (since the text you
quoted specifies that a null pointer return value signifies failure for
realloc).
> allocating 0 bytes can't be too difficult ;-)
<nit>realloc(p, 0), if it succeeded, hasn't allocated 0 bytes. It has
allocated one or more bytes, plus whatever information free needs to give
it back later.</nit>
Anyway, even if it weren't specifically allowed to always fail, it could
still for example fail on implementations where if the size is small,
*alloc returns pointers to pre-allocated buckets depending on the
requested size.


|