From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25561 invoked from network); 15 Nov 2005 11:03:22 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.0 (2005-09-13) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00, FORGED_RCVD_HELO autolearn=ham version=3.1.0 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 15 Nov 2005 11:03:22 -0000 Received: (qmail 40007 invoked from network); 15 Nov 2005 11:03:15 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 15 Nov 2005 11:03:15 -0000 Received: (qmail 2258 invoked by alias); 15 Nov 2005 11:03:13 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 22003 Received: (qmail 2249 invoked from network); 15 Nov 2005 11:03:12 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 15 Nov 2005 11:03:12 -0000 Received: (qmail 39724 invoked from network); 15 Nov 2005 11:03:12 -0000 Received: from dsl3-63-249-88-2.cruzio.com (HELO dot.blorf.net) (63.249.88.2) by a.mx.sunsite.dk with SMTP; 15 Nov 2005 11:03:11 -0000 Received: by dot.blorf.net (Postfix, from userid 1000) id CBEA02968; Tue, 15 Nov 2005 03:03:09 -0800 (PST) Date: Tue, 15 Nov 2005 03:03:09 -0800 From: Wayne Davison To: zsh-workers@sunsite.dk Subject: Re: Removing forced casts between signed/unsigned char pointers Message-ID: <20051115110309.GA21211@dot.blorf.net> References: <20051115092720.GA13478@dot.blorf.net> <20051115100009.GA202@DervishD> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20051115100009.GA202@DervishD> User-Agent: Mutt/1.5.9i 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..