zsh-workers
 help / color / mirror / code / Atom feed
From: Wayne Davison <wayned@users.sourceforge.net>
To: zsh-workers@sunsite.dk
Subject: Re: Removing forced casts between signed/unsigned char pointers
Date: Tue, 15 Nov 2005 03:03:09 -0800	[thread overview]
Message-ID: <20051115110309.GA21211@dot.blorf.net> (raw)
In-Reply-To: <20051115100009.GA202@DervishD>

On Tue, Nov 15, 2005 at 11:00:09AM +0100, DervishD wrote:
> If you go for portability, you shouldn't assume that a plain char is
> equivalent to "unsigned char".

I'm not -- I'm assuming that "char" is probably signed while making sure
that the code works irrespective of it being signed or not.  What I want
to avoid is a bunch of switching back and forth between the two pointer
types.  I like to avoid pointer casts where possible because they can
hide bugs.  For instance, it's easy to think that we're casting one
pointer type to another when we're really forcibly casting a character
value or an int into a pointer -- the casts are coded the same way, and
C will not complain about it if it's an explicit cast.  (Yes, we could
use inline functions under a compiler like gcc and code up type-safe
conversions, but I think it's better to pick a single char type and
stick with it than to do a bunch of converting back and forth.)

> If you don't mind me suggesting, you should use "unsigned char"
> wherever possible, and cast to plain "char" when needed.

I certainly wouldn't mind if all of zsh were switched over to using
unsigned chars for its strings, but that's a MUCH larger change than
what I did (my changes mainly affected the ZLE code).  Switching all of
zsh to unsigned chars would also involve some kind of a wrapper scheme
for standard C functions that we use (e.g. strcpy(), strcmp(), strchr(),
etc.), which might be a little annoying, but probably wouldn't be too
bad.

The main thing zsh needs is consistency of type and good coding
practices to avoid any problems with signed characters.  Yes, such
coding practices are slightly easier to get right when using unsigned
chars, but zsh already has several idioms in place that are geared
towards making sure that signed characters are handled correctly.

That's my opinion, at least.

..wayne..


  reply	other threads:[~2005-11-15 11:03 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-15  9:27 Wayne Davison
2005-11-15 10:00 ` DervishD
2005-11-15 11:03   ` Wayne Davison [this message]
2005-11-15 12:15     ` DervishD

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=20051115110309.GA21211@dot.blorf.net \
    --to=wayned@users.sourceforge.net \
    --cc=zsh-workers@sunsite.dk \
    /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).