home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / std / c / 3057 < prev    next >
Encoding:
Internet Message Format  |  1992-11-23  |  1.6 KB

  1. Path: sparky!uunet!world!ksr!jfw
  2. From: jfw@ksr.com (John F. Woods)
  3. Newsgroups: comp.std.c
  4. Subject: Re: malloc(0)
  5. Message-ID: <19169@ksr.com>
  6. Date: 23 Nov 92 11:19:21 EST
  7. References: <1ejhrnINN5it@ftp.UU.NET> <1992Nov21.005207.9741@lucid.com> <3904@dozo.and.nl>
  8. Sender: news@ksr.com
  9. Lines: 24
  10.  
  11. jos@and.nl (Jos Horsmeier) writes:
  12. >In article <1992Nov21.005207.9741@lucid.com> jss@lucid.com (Jerry Schwarz) writes:
  13. >|The standard says  (refering to allocation routines)
  14. >|    If the size of the space requested is zero, the behavior
  15. >|    is implementation-defined; the value returned shall be
  16. >|    either a null pointer or a unique pointer.
  17. >|I have always read "unique pointer" as meaning different from
  18. >|previously allocated pointers including pointers previously
  19. >|returned by malloc(0).  However I have just been talking to
  20. >|some people who insist it means that the same pointer is returned
  21. >|on each call of malloc(0).
  22. >Quite an interesting question ... the answer all depends on the meaning
  23. >of the word `unique'.
  24.  
  25. Two sentences earlier, the same paragraph says "Each such allocation shall
  26. yield a pointer to an object disjoint from any other object."  malloc() et
  27. al always returns an object; each call results in an object disjoint from
  28. any other object; malloc(0) is therefore entitled to return either NULL
  29. or "an object disjoint from any other object".  Therefore,  malloc(0) may
  30. *not* keep returning pointers to the same dedicated zero-size "object"
  31. (unless, of course, that malloc()ed pointer is freed immediately each time).
  32.  
  33. Sometimes, you have to read more than one sentence to understand the C
  34. standard.
  35.