🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #2985

Re: malloc(0)

#2985
From: Jos Horsmeier
Date: Mon, 23 Nov 1992 10:41
38 lines
1714 bytes
In article <2305@sdrc.COM> scjones@thor.sdrc.com (Larry Jones) writes:
|In article <1992Nov21.005207.9741@lucid.com>, jss@lucid.com (Jerry Schwarz) writes:
|< The standard says  (refering to allocation routines)
|< 
|< 	If the size of the space requested is zero, the behavior
|< 	is implementation-defined; the value returned shall be
|< 	either a null pointer or a unique pointer.
|< 
|< I have always read "unique pointer" as meaning different from
|< previously allocated pointers including pointers previously
|< returned by malloc(0).
|
|That was indeed the committee's intent.  If every call for zero space
|returned the same pointer it wouldn't be very unique, would it?

No it wouldn't, but if it would return a unique pointer value,it would
brake code like this:

char *p= malloc(0);
char *q= malloc(0);

if (p == q)
	printf("malloc returned NULL or non-unique value"\n");
else
	printf("malloc returned two unique pointers\n");

when ported from a system where malloc(0) returns NULL to a system
where malloc would return a unique pointer every time it was 
called with a size of zero ...

regards,

Jos aka jos@and.nl

ps. Bill Mitchell (mitchell@mdd.comm.mot.com) quoted the rationale
    concerning this topic <1992Nov21.191712.1397@mdd.comm.mot.com>
    but the rationale doesn't say much about this (pathetic) little
    problem ...
Technical Details
Message-ID: <3918@dozo.and.nl>
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!sun4nl!and!jos
References: <1ejhrnINN5it@ftp.UU.NET> <1992Nov21.005207.9741@lucid.com> <2305@sdrc.COM>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!sun4nl!and!jos
From: jos@and.nl (Jos Horsmeier)
Newsgroups: comp.std.c
Subject: Re: malloc(0)
Message-ID: <3918@dozo.and.nl>
Date: 23 Nov 92 10:41:27 GMT
References: <1ejhrnINN5it@ftp.UU.NET> <1992Nov21.005207.9741@lucid.com> <2305@sdrc.COM>
Organization: AND Software BV Rotterdam
Lines: 40