delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1998/09/29/21:07:13

Sender: nate AT cartsys DOT com
Message-ID: <361182CA.BD6F9ED8@cartsys.com>
Date: Tue, 29 Sep 1998 18:00:58 -0700
From: Nate Eldredge <nate AT cartsys DOT com>
X-Mailer: Mozilla 4.05 [en] (X11; I; Linux 2.0.35 i486)
MIME-Version: 1.0
To: Ilya Ryzhenkov <orangy AT inetlab DOT com>
CC: djgpp workers list <djgpp-workers AT backup DOT delorie DOT com>
Subject: Re: Just a question
References: <3610D3F3 DOT 8DA204E0 AT inetlab DOT com>

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019