home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!world!ksr!jfw
- From: jfw@ksr.com (John F. Woods)
- Newsgroups: comp.std.c
- Subject: Re: malloc(0)
- Message-ID: <19171@ksr.com>
- Date: 23 Nov 92 11:24:55 EST
- References: <1ejhrnINN5it@ftp.UU.NET> <1992Nov21.005207.9741@lucid.com> <2305@sdrc.COM> <3918@dozo.and.nl>
- Sender: news@ksr.com
- Lines: 27
-
- jos@and.nl (Jos Horsmeier) writes:
- >In article <2305@sdrc.COM> scjones@thor.sdrc.com (Larry Jones) writes:
- >|That was indeed the committee's intent. If every call for zero space
- >|returned the same pointer it wouldn't be very unique, would it?
- >No it wouldn't, but if it would return a unique pointer value,it would
- >brake code like this:
- >char *p= malloc(0);
- >char *q= malloc(0);
- >if (p == q)
- > printf("malloc returned NULL or non-unique value"\n");
- >else
- > printf("malloc returned two unique pointers\n");
-
- I would certainly hope it would brake code like that. Putting a stop to
- code like that is valuable. :-)
-
- >when ported from a system where malloc(0) returns NULL to a system
- >where malloc would return a unique pointer every time it was
- >called with a size of zero ...
-
- Anyone who tests for whether or not malloc(0) returned NULL by testing
- whether or not the new malloc(0) returned the same as a previous malloc(0)
- deserves to have their programming career braked, too.
-
- [For the non-native English speakers in the audience, in between the valid
- technical points here I am having fun with Jos' misspelling of "break" (to
- damage or destroy) as "brake" (to slow or stop).]
-