From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mike Gran Newsgroups: gmane.lisp.guile.devel Subject: Re: unsigned char confusion Date: Tue, 11 Aug 2009 08:23:23 -0700 Message-ID: <1250004203.30365.67.camel@localhost.localdomain> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1250004246 31888 80.91.229.12 (11 Aug 2009 15:24:06 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 11 Aug 2009 15:24:06 +0000 (UTC) Cc: guile-devel To: Greg Troxel Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Tue Aug 11 17:24:00 2009 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MatCh-00054R-IW for guile-devel@m.gmane.org; Tue, 11 Aug 2009 17:24:00 +0200 Original-Received: from localhost ([127.0.0.1]:52180 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MatCf-0008Ha-QL for guile-devel@m.gmane.org; Tue, 11 Aug 2009 11:23:57 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MatCZ-0008HF-Oh for guile-devel@gnu.org; Tue, 11 Aug 2009 11:23:51 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MatCZ-0008Go-3p for guile-devel@gnu.org; Tue, 11 Aug 2009 11:23:51 -0400 Original-Received: from [199.232.76.173] (port=47806 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MatCY-0008Gl-WC for guile-devel@gnu.org; Tue, 11 Aug 2009 11:23:51 -0400 Original-Received: from smtp109.prem.mail.sp1.yahoo.com ([98.136.44.54]:33954) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1MatCY-0005da-J6 for guile-devel@gnu.org; Tue, 11 Aug 2009 11:23:50 -0400 Original-Received: (qmail 33186 invoked from network); 11 Aug 2009 15:23:49 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Received:X-Yahoo-SMTP:X-YMail-OSG:X-Yahoo-Newman-Property:Subject:From:To:Cc:In-Reply-To:References:Content-Type:Date:Message-Id:Mime-Version:X-Mailer:Content-Transfer-Encoding; b=Q9vynAtwDWSG1mqFwmRUmAzdLy5Ybc0tgdmNpAS5pY8dwlhmb9Ykkz/jvSGqYlWbixRY5TWNRey86SvoKE3v/dfxfHG3GaZ+T8qR/d2kbO+TcxNAHG6EKQR7+U7oFrnRh4Fw/5402qG0IWVkxkW7phNNrgrXXEjfpmvrT6R84cw= ; Original-Received: from ppp-71-142-0-233.dsl.irvnca.pacbell.net (spk121@71.142.0.233 with plain) by smtp109.prem.mail.sp1.yahoo.com with SMTP; 11 Aug 2009 08:23:49 -0700 PDT X-Yahoo-SMTP: FzNaA9iswBDuBl1BmgaIRDaP9Q-- X-YMail-OSG: QY...TwVM1kgwr6KjPobDxM5GeepdH1TtD.ABxgaOZMQzEV2KCyjMIYhy_j30tdZBhpyAszfr24AZZ1hDm7CZMYm.CzL_iKHs.T9uvM905oU23WY9rV0JmwKhr0PpuXR_8DWIG35NyJ0J0bai39l84At8w8kYFkFpjfl5lCVcmVOwwynTCN2nFLVhW9PyOZFL3FxZqEX3Hh8r1Dyk2kgXpbNtTqHEFSo9_u21Ll1kms7xo8hKxTS4aXO2LDSc8mmI.bgmadJMnlj98V76wIHYw0n9R3F.CpXOpRtfK1g855weaCqHMYtE3jwJZ2VX2Wa2ok- X-Yahoo-Newman-Property: ymail-3 In-Reply-To: X-Mailer: Evolution 2.24.5 (2.24.5-2.fc10) X-detected-operating-system: by monty-python.gnu.org: FreeBSD 4.7-5.2 (or MacOS X 10.2-10.4) (2) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:9060 Archived-At: On Tue, 2009-08-11 at 09:39 -0400, Greg Troxel wrote: > In srfi-13.c line 25222, SCM_MAKE_CHAR is called with an argument that > is an unsigned char. This leads to: > > cc1: warnings being treated as errors > srfi-13.c: In function 'string_titlecase_x': > srfi-13.c:2522: warning: comparison is always false due to limited range of data type > srfi-13.c:2522: warning: comparison is always false due to limited range of data type > > This is because SCM_MAKE_CHAR (in libguile/chars.h) has a bizarre > conditional that checks the argument for < 0, and if so casts it to > unsigned char. Otherwise it does not cast. There is no comment that > explains what the point is. Fairly obviously this is an attempt to > avoid sign extension during SCM_MAKE_ITAG8. The value is then cast to > uintptr_t which is also unsigned, but sign extension would set more > bits. > > So, I think the cast to unsigned char should just always be there, without the test. > Yeah, that was me. In the move to Unicode, I'm trying to get to a point where the underlying storage of characters is uint32. I was trying to come up with a macro that would cast all of char, unsigned char, and uint32 to uint32, since SCM_MAKE_CHAR is used in each of those cases in the code. If SCM_MAKE_CHAR receives something negative, it is from a signed char. For portability, it might be best if SCM_MAKE_CHAR becomes an inline function that takes int32, since the top bit of uint32 isn't used in encoding Unicode codepoints anyway. That would cover all those cases. Or, to save the macro, it could become #define SCM_MAKE_CHAR(x) \ (((scm_t_int32) (x) < 0) \ ? SCM_MAKE_ITAG8 ((scm_t_bits) (unsigned char) (x), scm_tc8_char) \ : SCM_MAKE_ITAG8 ((scm_t_bits) (x), scm_tc8_char)) Yeah, and better comments for that as well. -Mike