home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!gatech!concert!duke!trt
- From: trt@duke.cs.duke.edu (Tom Truscott)
- Newsgroups: comp.unix.aix
- Subject: Re: malloc(0) fails on AIX ... etc.
- Message-ID: <726705103@romeo.cs.duke.edu>
- Date: 10 Jan 93 22:31:44 GMT
- References: <31480@nntp_server.ems.cdc.com> <1993Jan9.161925.5124@idsssd.UUCP>
- Organization: IBM RTP
- Lines: 26
-
- > But, think of the threads that would open complaining that "it doesn't error
- > when I malloc(0) ... shouldn't it return an error?" ...
-
- I don't think this would happen. malloc(0) for years has returned a unique
- pointer on SunOS, Ultrix, HP-UX, ... and I have yet to see anyone complain.
- On the other hand I have seen a never ending stream of complaints
- about systems where malloc(0) fails.
-
- The only argument I have *ever* heard for malloc(0) failing is that
- it is "required by the SVID". (Could someone please quote chapter
- and verse where it is required, and not merely permitted?)
- Does 100% SVID compliance make AIX dead right?
-
- Of course portable programs must defend against malloc() nonsense.
- (The correct coding is non-obvious, as previous articles have revealed.)
- But this is a poor justification for continuing the AIX malloc behavior!
-
- This thread reminds me of the ancient debate about left-shifting by 0.
- In some C implementations (i << n) was undefined when n == 0
- since the hardware did not efficiently support it.
- There were people who didn't want to see left shift slowed down just
- to handle a dubious and rare special case.
- After all, this could be handled portably with:
- (n == 0)? i: (i << n)
-
- Tom Truscott
-