home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!pipex!warwick!uknet!axion!nwinton
- From: nwinton@axion.bt.co.uk (Neil Winton)
- Newsgroups: comp.unix.aix
- Subject: Re: malloc(0) fails on AIX and nowhere else I could find ...
- Message-ID: <C0HCs4.Eoy@axion.bt.co.uk>
- Date: 7 Jan 93 10:50:26 GMT
- References: <93Jan7.012526est.169557-2@watdragon.uwaterloo.ca>
- Sender: news@axion.bt.co.uk
- Organization: BT Laboratories
- Lines: 37
-
- In article <93Jan7.012526est.169557-2@watdragon.uwaterloo.ca>, jmsellen@watdragon.uwaterloo.ca ("John M. Sellens") writes:
- |> Just in case anyone is interested:
- |>
- |> Trying to malloc() 0 bytes on AIX fails, but works on Ultrix, IRIX,
- |> Dynix, SunOS, BSD, MIPS RiscOS.
-
- Pardon? What do you mean `it works'? Sure it returns a non-null pointer but
- what are you going to do with that? You asked for no space to be allocated so
- how are you going to use that pointer-to-nothing??? For your information,
- AIX is not the only system which will give you a null pointer -- so will
- Solaris 2 (SVR4) if you link with -lmalloc.
-
- |> OK, it's documented in the man page on AIX, but it's a pointless and
- |> annoying inconsistency. I wish AIX was UNIX.
-
- Actually, documenting it is EXACTLY what AIX should do according to the ANSI
- (ISO) C standard. ISO/IEC 9899:1990 (E) Section 7.10.3 says:
-
- 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.
-
- So don't rely on malloc(0) doing anything portable!
-
- There are times when I'm glad that AIX is not UNIX-as-we-know-and-love-it! I'm
- concerned with writing portable code and it's sometimes really useful to have a
- platform which interprets standards in a different, but legal, manner.
-
- |> John Sellens
- |> University of Waterloo
- |> jmsellens@watdragon.uwaterloo.ca
-
- * Neil Winton BT Labs, Rm 306 SSTF, Martlesham Heath *
- * N.Winton@axion.bt.co.uk IPSWICH IP5 7RE, UK (Tel +44 473 646079) *
- * The works of the Lord are great, sought out of all them that have *
- * pleasure therein. Psalm 111 v 2 *
- * (Found at the entrance to the Cavendish Labs, Cambridge.) *
-