From owner-freebsd-stable@FreeBSD.ORG Sat Aug 12 18:47:14 2006 Return-Path: X-Original-To: freebsd-stable@freebsd.org Delivered-To: freebsd-stable@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id BAFC416A4DA; Sat, 12 Aug 2006 18:47:14 +0000 (UTC) (envelope-from rivers@dignus.com) Received: from dignus.com (mail.dignus.com [209.42.196.2]) by mx1.FreeBSD.org (Postfix) with ESMTP id 09F4043D46; Sat, 12 Aug 2006 18:47:13 +0000 (GMT) (envelope-from rivers@dignus.com) Received: from lakes.dignus.com (lakes.dignus.com [10.1.0.3]) by dignus.com (8.13.1/8.13.1) with ESMTP id k7CIiIIL037121; Sat, 12 Aug 2006 14:44:18 -0400 (EDT) (envelope-from rivers@dignus.com) Received: (from rivers@localhost) by lakes.dignus.com (8.11.6/8.11.3) id k7CInB612383; Sat, 12 Aug 2006 14:49:11 -0400 (EDT) (envelope-from rivers) Date: Sat, 12 Aug 2006 14:49:11 -0400 (EDT) From: Thomas David Rivers Message-Id: <200608121849.k7CInB612383@lakes.dignus.com> To: bu7cher@yandex.ru, marck@rinet.ru In-Reply-To: <20060812212327.Q25511@woozle.rinet.ru> X-Spam-Status: No, score=-2.8 required=5.0 tests=ALL_TRUSTED autolearn=failed version=3.0.1 X-Spam-Checker-Version: SpamAssassin 3.0.1 (2004-10-22) on office.dignus.com Cc: kostikbel@gmail.com, maxim@freebsd.org, freebsd-stable@freebsd.org Subject: Re: setlocale howto X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 12 Aug 2006 18:47:14 -0000 Dmitry Morozovsky wrote: > > On Sat, 12 Aug 2006, Andrey V. Elsukov wrote: > > AVE> >On Sat, Aug 12, 2006 at 05:51:01PM +0400, Andrey V. Elsukov wrote: > AVE> >> for(i = 0; i < sizeof(buf); i++) > AVE> >> buf[i] = (char)toupper(buf[i]); > AVE> > > AVE> > buf[i] = (char)toupper((unsigned char)buf[i]); > AVE> >Standard integer promotion promotes KOI8-R char codes like 0xd4 into 0xffffffd4. > AVE> >Since such codepoints are not defined for KOI8-R, toupper returns them > AVE> >unchaged, as specified in documentation. > AVE> > AVE> Thanks, this works! But why this example works on Linux without type conversions? > > Linux has unsigned chars by default, while FreeBSD (and other current *BSDs) > signed. > > Even large projects like PostgreSQL stepped into this trap at least once ;-) > > Sincerely, > D.Marck [DM5020, MCK-RIPE, DM3-RIPN] "Linux" does not have unsigned char by default. This is a log from an x86 LINUX machine: [linux]$ cat c.c main() { char c; unsigned char uc; c = -1; uc = -1; printf("c is %d\n", c); printf("uc is %d\n", uc); } [linux]$ uname Linux [linux]$ ./a.out c is -1 uc is 255 The signedness of char is usually a hardware-related issue. If the hardware provides a single instruction to load-and-sign-extend a character, then char will typically be signed; if the hardware's instruction to load a char (or a byte) does not sign-extend, then the char will be unsigned. For example, Linux on an IBM mainframe uses unsigned as the default for 'char', while x86 Linux uses signed. So, it could easily be that your particular Linux (on a particular hardware implementation) uses unsigned as the default signedness for char. - Dave Rivers - -- rivers@dignus.com Work: (919) 676-0847 Get your mainframe programming tools at http://www.dignus.com