zsh-workers
 help / color / mirror / code / Atom feed
From: Zefram <A.Main@dcs.warwick.ac.uk>
To: coleman@math.gatech.edu (Richard Coleman)
Cc: zsh-workers@math.gatech.edu
Subject: Re: (NULL == 0) ?
Date: Sat, 25 May 1996 23:00:23 +0100 (BST)	[thread overview]
Message-ID: <15522.199605252200@stone.dcs.warwick.ac.uk> (raw)
In-Reply-To: <199605252125.RAA21046@redwood.skiles.gatech.edu> from "Richard Coleman" at May 25, 96 05:25:35 pm

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



  reply	other threads:[~1996-05-25 22:14 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-05-25 14:38 clwords bugfix Zefram
1996-05-25 18:02 ` Richard Coleman
1996-05-25 20:52   ` Zefram
1996-05-25 21:25     ` (NULL == 0) ? Richard Coleman
1996-05-25 22:00       ` Zefram [this message]
1996-05-27  0:00         ` Zoltan Hidvegi
1996-05-27  6:39           ` Bart Schaefer
1996-05-27  7:29             ` anthony baxter
1996-05-27 13:07           ` Zefram
1996-05-27 22:00             ` Zoltan Hidvegi
1996-05-27 22:11               ` Zefram
1996-05-27 22:41                 ` Zoltan Hidvegi
1996-05-27 22:54                   ` Zefram
1996-05-28  4:54                     ` Bart Schaefer
1996-05-27 23:36                 ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=15522.199605252200@stone.dcs.warwick.ac.uk \
    --to=a.main@dcs.warwick.ac.uk \
    --cc=coleman@math.gatech.edu \
    --cc=zsh-workers@math.gatech.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).