Walter Roberson wrote:
> Francois Grieu <> wrote:
>
>> When running the following code under MinGW, I get
>> realloc(p,0) returned NULL
>> Is that a non-conformance?
>
> No, it is conformance, and returning non-NULL would be non-conformance.
>
.... snip C89 quote ...
C99 quote:
7.20.3 Memory management functions
[#1] The order and contiguity of storage allocated by
successive calls to the calloc, malloc, and realloc
functions is unspecified. The pointer returned if the
allocation succeeds is suitably aligned so that it may be
assigned to a pointer to any type of object and then used to
access such an object or an array of such objects in the
space allocated (until the space is explicitly freed or
reallocated). Each such allocation shall yield a pointer to
an object disjoint from any other object. The pointer
returned points to the start (lowest byte address) of the
allocated space. If the space cannot be allocated, a null
pointer is returned. If the size of the space requested is <
zero, the behavior is implementation-defined: either a null <
pointer is returned, or the behavior is as if the size were <
some nonzero value, except that the returned pointer shall <
not be used to access an object. The value of a pointer <
that refers to freed space is indeterminate. <
Note that either a NULL or an individual pointer can be returned.
The pointer to a zero size space can't be dereferenced. You also
can't positively tell a malloc system error from success. So I
advise always allocating (or reallocing) 1 or more bytes.
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
--
Posted via a free Usenet account from
http://www.teranews.com