Re: More questions on realloc - Thanks
- From: "S.Tobias" <siXtY@xxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: 30 Nov 2005 13:43:56 GMT
Jordan Abel <jmabel@xxxxxxxxxx> wrote:
> On 2005-11-29, S.Tobias <siXtY@xxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
>> James S. Singleton <pt109@xxxxxxxxxx> wrote:
>>> b) Implementing realloc(ptr, size) using malloc(), memcpy() and free()
>>> alone, without knowing the size of the memory region pointed to by ptr, is
>>> just not possible.
>>
>> True, in standard C it's not possible.
>>
>> But note that `malloc' and `free' are redundant and can be implemented
>> in terms of `realloc'.
>
> free() can't, unless a size request of 0 does not cause an allocation
> [which is not guaranteed.]
#include <stdlib.h>
void my_free(void *p) { while(p = realloc(p,0)) ; }
;-)
Yes, you're right, I was wrong. `realloc(p,0)' is *not* equivalent
to `free(p)' (for non-null `p'). I knew it once, but forgot.
Thank you!
--
Stan Tobias
mailx `echo siXtY@xxxxxxxxxxxxxxxxxxxxxxxxxx | sed s/[[:upper:]]//g`
.
- Follow-Ups:
- Re: More questions on realloc - Thanks
- From: Nils Weller
- Re: More questions on realloc - Thanks
- Prev by Date: Re: How to redefine arithmetic operators.
- Next by Date: Re: Type punning
- Previous by thread: Re: How to redefine arithmetic operators.
- Next by thread: Re: More questions on realloc - Thanks
- Index(es):
Relevant Pages
|