home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / std / c / 3055 < prev    next >
Encoding:
Text File  |  1992-11-22  |  1.6 KB  |  51 lines

  1. Path: sparky!uunet!mcsun!sun4nl!and!jos
  2. From: jos@and.nl (Jos Horsmeier)
  3. Newsgroups: comp.std.c
  4. Subject: Re: malloc(0)
  5. Message-ID: <3918@dozo.and.nl>
  6. Date: 23 Nov 92 10:41:27 GMT
  7. References: <1ejhrnINN5it@ftp.UU.NET> <1992Nov21.005207.9741@lucid.com> <2305@sdrc.COM>
  8. Organization: AND Software BV Rotterdam
  9. Lines: 40
  10.  
  11. In article <2305@sdrc.COM> scjones@thor.sdrc.com (Larry Jones) writes:
  12. |In article <1992Nov21.005207.9741@lucid.com>, jss@lucid.com (Jerry Schwarz) writes:
  13. |< The standard says  (refering to allocation routines)
  14. |< 
  15. |<     If the size of the space requested is zero, the behavior
  16. |<     is implementation-defined; the value returned shall be
  17. |<     either a null pointer or a unique pointer.
  18. |< 
  19. |< I have always read "unique pointer" as meaning different from
  20. |< previously allocated pointers including pointers previously
  21. |< returned by malloc(0).
  22. |
  23. |That was indeed the committee's intent.  If every call for zero space
  24. |returned the same pointer it wouldn't be very unique, would it?
  25.  
  26. No it wouldn't, but if it would return a unique pointer value,it would
  27. brake code like this:
  28.  
  29. char *p= malloc(0);
  30. char *q= malloc(0);
  31.  
  32. if (p == q)
  33.     printf("malloc returned NULL or non-unique value"\n");
  34. else
  35.     printf("malloc returned two unique pointers\n");
  36.  
  37. when ported from a system where malloc(0) returns NULL to a system
  38. where malloc would return a unique pointer every time it was 
  39. called with a size of zero ...
  40.  
  41. regards,
  42.  
  43. Jos aka jos@and.nl
  44.  
  45. ps. Bill Mitchell (mitchell@mdd.comm.mot.com) quoted the rationale
  46.     concerning this topic <1992Nov21.191712.1397@mdd.comm.mot.com>
  47.     but the rationale doesn't say much about this (pathetic) little
  48.     problem ...
  49.  
  50.  
  51.