From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from euclid.skiles.gatech.edu (list@euclid.skiles.gatech.edu [130.207.146.50]) by melb.werple.net.au (8.7.5/8.7.3) with ESMTP id IAA09822 for ; Sun, 26 May 1996 08:14:07 +1000 (EST) Received: (from list@localhost) by euclid.skiles.gatech.edu (8.7.3/8.7.3) id SAA08234; Sat, 25 May 1996 18:00:31 -0400 (EDT) Resent-Date: Sat, 25 May 1996 18:00:31 -0400 (EDT) From: Zefram Message-Id: <15522.199605252200@stone.dcs.warwick.ac.uk> Subject: Re: (NULL == 0) ? To: coleman@math.gatech.edu (Richard Coleman) Date: Sat, 25 May 1996 23:00:23 +0100 (BST) Cc: zsh-workers@math.gatech.edu In-Reply-To: <199605252125.RAA21046@redwood.skiles.gatech.edu> from "Richard Coleman" at May 25, 96 05:25:35 pm X-Loop: zefram@dcs.warwick.ac.uk X-Stardate: [-31]7559.58 X-US-Congress: Moronic fuckers MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Resent-Message-ID: <"Fpt541.0.X02.-Bufn"@euclid> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/1178 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu To answer the subject line, (NULL == 0) *is* guaranteed. 0 is the representation of the null pointer constant in C. >I would be willing to bet money it's a non-unix box. Just think of >the tremendous amount of unix code that uses the fact that calloc (in >our case zcalloc) returns memory that is all zeros (and hence is >NULL). Since zsh only works on unix boxes, I think zeroing out memory >with memset is ok. A lot of C code assumes this, but it is broken. No Unix standard guarantees more than the C standard about the representation of null pointers. >I'm no expert on compilers, but I would be surprised if gcc could >optimize such a loop to be as fast as memset. Usually memset is >hand optimized assembler code. True, it generally won't be as good, but GCC does produce very efficient code. And the speed isn't really critical -- for example, in this particular case, the code is only executed when you complete on a command line with 16 words, and it then only needs to assign to 16 pointers. (It could only cause a crash when you reach 32 words, and on my system it took 64.) >The function `newhashtable' uses zcalloc to allocate hashtable memory >and the function `emptyhashtable' uses memset to set this same memory >to zero when it is emptied. If assuming NULL was equal to 0 would >crash a machine, then these two pieces of code would have done it a >long time ago. The hashtable code gets executed a lot. I can believe that zsh is not currently being used on any system where the null pointer is not all-bits-zero. Consequently it's not a really important issue. But code that makes this assumption is ill-formed. -zefram