home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / unix / aix / 13085 < prev    next >
Encoding:
Internet Message Format  |  1993-01-07  |  2.1 KB

  1. Path: sparky!uunet!pipex!warwick!uknet!axion!nwinton
  2. From: nwinton@axion.bt.co.uk (Neil Winton)
  3. Newsgroups: comp.unix.aix
  4. Subject: Re: malloc(0) fails on AIX and nowhere else I could find ...
  5. Message-ID: <C0HCs4.Eoy@axion.bt.co.uk>
  6. Date: 7 Jan 93 10:50:26 GMT
  7. References: <93Jan7.012526est.169557-2@watdragon.uwaterloo.ca>
  8. Sender: news@axion.bt.co.uk
  9. Organization: BT Laboratories
  10. Lines: 37
  11.  
  12. In article <93Jan7.012526est.169557-2@watdragon.uwaterloo.ca>, jmsellen@watdragon.uwaterloo.ca ("John M. Sellens") writes:
  13. |> Just in case anyone is interested:
  14. |> 
  15. |> Trying to malloc() 0 bytes on AIX fails, but works on Ultrix, IRIX,
  16. |> Dynix, SunOS, BSD, MIPS RiscOS.
  17.  
  18. Pardon?  What do you mean `it works'?  Sure it returns a non-null pointer but
  19. what are you going to do with that?  You asked for no space to be allocated so
  20. how are you going to use that pointer-to-nothing???  For your information,
  21. AIX is not the only system which will give you a null pointer -- so will
  22. Solaris 2 (SVR4) if you link with -lmalloc.
  23.  
  24. |> OK, it's documented in the man page on AIX, but it's a pointless and
  25. |> annoying inconsistency.  I wish AIX was UNIX.
  26.  
  27. Actually, documenting it is EXACTLY what AIX should do according to the ANSI
  28. (ISO) C standard.  ISO/IEC 9899:1990 (E) Section 7.10.3 says:
  29.  
  30.     If the size of the space requested is zero, the behavior is
  31.     implementation-defined; the value returned shall be either a null
  32.     pointer or a unique pointer.
  33.  
  34. So don't rely on malloc(0) doing anything portable!
  35.  
  36. There are times when I'm glad that AIX is not UNIX-as-we-know-and-love-it!  I'm
  37. concerned with writing portable code and it's sometimes really useful to have a
  38. platform which interprets standards in a different, but legal, manner.
  39.  
  40. |> John Sellens
  41. |> University of Waterloo
  42. |> jmsellens@watdragon.uwaterloo.ca
  43.  
  44. *   Neil Winton            BT Labs, Rm 306 SSTF, Martlesham Heath     *
  45. *   N.Winton@axion.bt.co.uk    IPSWICH IP5 7RE, UK   (Tel +44 473 646079) *
  46. *    The works of the Lord are great, sought out of all them that have     *
  47. *    pleasure therein.                     Psalm 111 v 2     *
  48. *        (Found at the entrance to the Cavendish Labs, Cambridge.)         *
  49.