Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Re: Can realloc...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 14 of 15 Topic 24830 of 28006
Post > Topic >>

Re: Can realloc(p,0) return NULL when p is non-NULL and memory

by Harald van =?UTF-8?b?RMSzaw==?= <truedfx@[EMAIL PROTECTED] > Mar 6, 2008 at 07:48 PM

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.
 




 15 Posts in Topic:
Can realloc(p,0) return NULL when p is non-NULL and memory aplen
Francois Grieu <fgrieu  2008-03-06 09:54:23 
Re: Can realloc(p,0) return NULL when p is non-NULL and memory a
"Joachim Schmitz&quo  2008-03-06 19:01:31 
Re: Can realloc(p,0) return NULL when p is non-NULL and memory a
roberson@[EMAIL PROTECTED  2008-03-06 18:03:02 
Re: Can realloc(p,0) return NULL when p is non-NULL and memory a
"Joachim Schmitz&quo  2008-03-06 19:18:40 
Re: Can realloc(p,0) return NULL when p is non-NULL and memory a
"Joachim Schmitz&quo  2008-03-06 19:20:52 
Re: Can realloc(p,0) return NULL when p is non-NULL and memory a
"Joachim Schmitz&quo  2008-03-06 19:23:25 
Re: Can realloc(p,0) return NULL when p is non-NULL and memory a
CBFalconer <cbfalconer  2008-03-06 15:19:07 
Re: Can realloc(p,0) return NULL when p is non-NULL and memory a
"Joachim Schmitz&quo  2008-03-07 09:04:50 
Re: Can realloc(p,0) return NULL when p is non-NULL and memory a
Micah Cowan <micah@[EM  2008-03-07 17:40:55 
Re: Can realloc(p,0) return NULL when p is non-NULL and memory
Harald van =?UTF-8?b?RMSz  2008-03-06 19:23:28 
Re: Can realloc(p,0) return NULL when p is non-NULL and memory
"Joachim Schmitz&quo  2008-03-06 19:31:30 
Re: Can realloc(p,0) return NULL when p is non-NULL and memory
roberson@[EMAIL PROTECTED  2008-03-06 18:32:18 
Re: Can realloc(p,0) return NULL when p is non-NULL and memory
Francois Grieu <fgrieu  2008-03-06 10:47:58 
Re: Can realloc(p,0) return NULL when p is non-NULL and memory
Harald van =?UTF-8?b?RMSz  2008-03-06 19:48:53 
Re: Can realloc(p,0) return NULL when p is non-NULL and memory a
Falcon Kirtaran <falco  2008-03-06 19:53:10 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Nov 21 12:21:38 CST 2008.