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 HAA09451 for ; Sun, 26 May 1996 07:41:26 +1000 (EST) Received: (from list@localhost) by euclid.skiles.gatech.edu (8.7.3/8.7.3) id RAA07857; Sat, 25 May 1996 17:25:52 -0400 (EDT) Resent-Date: Sat, 25 May 1996 17:25:52 -0400 (EDT) Message-Id: <199605252125.RAA21046@redwood.skiles.gatech.edu> To: zsh-workers@math.gatech.edu Subject: Re: (NULL == 0) ? In-reply-to: Your message of "Sat, 25 May 1996 21:52:09 BST." <13043.199605252052@stone.dcs.warwick.ac.uk> Date: Sat, 25 May 1996 17:25:35 -0400 From: Richard Coleman Resent-Message-ID: <"gVU3I1.0.hw1.Whtfn"@euclid> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/1177 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu > >What Unix has a NULL that isn't all-bits-zero? > > I'm not sure about Unices, but the C FAQ does list more than one system. 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. > > That would break > >a tremendous amount of code. There all lots of places in zsh > >that assume this and use memset. I don't think we should change > >this. > > I haven't noticed any other places that use memset for this purpose. I > only noticed this one because I was looking for this particular bug. I > think if there are other places that do this we should fix them because > they are broken. GCC can probably optimise looped assignments to be > almost as good as memset on systems where NULL is all-bits-zero. 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. 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. rc