Re: malloc realloc and pointers
- From: Harald van Dijk <truedfx@xxxxxxxxx>
- Date: Thu, 29 Nov 2007 22:18:14 +0000 (UTC)
On Thu, 29 Nov 2007 17:00:05 -0500, Kenneth Brody wrote:
ravi wrote:
2. With realloc(), if some pointer 'ptr' is pointing initially to a
perticular position in a buffer (char *buffer) then on performing a
realloc() on this buffer, what will be 'ptr' pointing to?
Three possibilities:
1) realloc() returns the same pointer, in which case ptr is still
valid, pointing to the newly-sized buffer.
According to DR #260, applied to realloc, even if memcmp proves the new
pointer is identical to the old pointer, you're not allowed to use them
interchangeably. If you pass a non-null pointer ptr to realloc, and it
doesn't return a null pointer, ptr is no longer valid.
(I do not believe the DR's conclusions can be drawn from any
interpretation of the actual standard, and in fact I believe some points
from the DR directly contradict explicit guarantees by the standard, but
that's just me.)
.
- References:
- malloc realloc and pointers
- From: ravi
- Re: malloc realloc and pointers
- From: Kenneth Brody
- malloc realloc and pointers
- Prev by Date: Re: malloc realloc and pointers
- Next by Date: pointers as parameters
- Previous by thread: Re: malloc realloc and pointers
- Next by thread: Re: malloc realloc and pointers
- Index(es):
Relevant Pages
|