lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> I do not know what the ANSI C standard says about using
> realloc(x,0).

ANSI C99 about memory management functions in general:

       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.

and about realloc itself [the part where free is mentioned]:

       If the realloc function returns a  null  pointer
       when  size is zero and ptr is not a null pointer, the object
       it pointed to has been freed.

So it seems one cannot depend on realloc(x,0) to free x and my
libc is not buggy (puh *g*).  Perfectly legal behaviour: truncate
to some small size and return a valid and unique pointer.

Ciao, ET.