Mail Archives: djgpp-workers/1998/09/29/21:07:13
Ilya Ryzhenkov wrote:
>
> Hi!
>
> Is there any standards of what should malloc(0) return ?
> Should it return NULL or a valid address with zero (actually
> minimum chunk) size ?
The OpenGroup spec says that it may either return NULL or a cookie
(presumably a valid address) that can be passed to `free'. Personally,
I would be inclined to return NULL, since dereferencing the pointer
would be an error.
http://www.opengroup.org/onlinepubs/7908799/xsh/malloc.html
> And, as a dependent, how must realloc(ptr,0) behave ? Should it
> be equal to free(ptr) and return NULL or behave in other way ?
It's freed, and returns, like malloc(0), either NULL or a meaningless
cookie.
http://www.opengroup.org/onlinepubs/7908799/xsh/realloc.html
--
Nate Eldredge
nate AT cartsys DOT com
- Raw text -