This is the mail archive of the libc-hacker@sourceware.cygnus.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: malloc(0)


   Date: Mon, 01 Jun 1998 09:54:21 -0400
   From: Zack Weinberg <zack@rabi.phys.columbia.edu>

   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.

I would prefer to return a non-null pointer, because then we can
guarantee that malloc(N) != malloc(N) for two different calls to
malloc.  That's a nice invariant to have.

Frequently it's handy to have loops in which the bottom case is a
zero-length malloc and have it Just Work.  This would break such
situations.

Could you describe what `peculiar characteristics' a malloc of zero
length has?

Thomas



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]