Article View: comp.std.c
Article #2986Re: malloc(0)
From: John F. Woods
Date: Mon, 23 Nov 1992 16:19
Date: Mon, 23 Nov 1992 16:19
24 lines
1647 bytes
1647 bytes
jos@and.nl (Jos Horsmeier) 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). However I have just been talking to >|some people who insist it means that the same pointer is returned >|on each call of malloc(0). >Quite an interesting question ... the answer all depends on the meaning >of the word `unique'. Two sentences earlier, the same paragraph says "Each such allocation shall yield a pointer to an object disjoint from any other object." malloc() et al always returns an object; each call results in an object disjoint from any other object; malloc(0) is therefore entitled to return either NULL or "an object disjoint from any other object". Therefore, malloc(0) may *not* keep returning pointers to the same dedicated zero-size "object" (unless, of course, that malloc()ed pointer is freed immediately each time). Sometimes, you have to read more than one sentence to understand the C standard.
Technical Details
Message-ID:
<19169@ksr.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!world!ksr!jfwReferences:
<1ejhrnINN5it@ftp.UU.NET> <1992Nov21.005207.9741@lucid.com> <3904@dozo.and.nl>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!world!ksr!jfw From: jfw@ksr.com (John F. Woods) Newsgroups: comp.std.c Subject: Re: malloc(0) Message-ID: <19169@ksr.com> Date: 23 Nov 92 11:19:21 EST References: <1ejhrnINN5it@ftp.UU.NET> <1992Nov21.005207.9741@lucid.com> <3904@dozo.and.nl> Sender: news@ksr.com Lines: 24