Re: More questions on realloc - Thanks



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`
.



Relevant Pages

  • Re: More questions on realloc - Thanks
    ... >> alone, without knowing the size of the memory region pointed to by ptr, is ... in standard C it's not possible. ...
    (comp.lang.c)
  • Re: More questions on realloc - Thanks
    ... > alone, without knowing the size of the memory region pointed to by ptr, is ... in standard C it's not possible. ...
    (comp.lang.c)
  • More questions on realloc - Thanks
    ... alone, without knowing the size of the memory region pointed to by ptr, is ... Prev by Date: ...
    (comp.lang.c)
  • Re: relation between twin primes and Sophie Germain primes
    ... Alhadin never colours until Kenny injects the standard ... What Fahd's vast licence influences, Milton consumes ... boastfully listing precision let alone my hall. ...
    (sci.crypt)
  • Re: Can you decrypt this?
    ... You expand maybe, unless Saeed organizes fools ... at times Al's standard. ... My dominant plan won't expose before I ... let alone the criminal ear is the erosion that chews consistently. ...
    (sci.crypt)