This is the mail archive of the
libc-hacker@sourceware.cygnus.com
mailing list for the glibc project.
Re: malloc(0)
- To: zack@rabi.phys.columbia.edu (Zack Weinberg)
- Subject: Re: malloc(0)
- From: hjl@lucon.org (H.J. Lu)
- Date: Mon, 1 Jun 1998 07:21:50 -0700 (PDT)
- Cc: libc-hacker@cygnus.com
>
>
> There's been some discussion recently in comp.std.c about what
> malloc(0) and realloc(x, 0) are supposed to do. The standard allows
> returning some non-null pointer in both cases, which is what we
> currently do. However, that non-null pointer has peculiar
> characteristics and it seems to me that it would be less surprising if
> both these operations returned NULL.
>
We used to have it return 0. But we changed it to return 1. I don't
remember what finally convinced us to do so. If the current scheme
is ANSI C compliant, don't change it.
H.J.
- References:
- malloc(0)
- From: Zack Weinberg <zack@rabi.phys.columbia.edu>