From owner-freebsd-stable@FreeBSD.ORG Thu May 24 12:14:26 2007 Return-Path: X-Original-To: freebsd-stable@FreeBSD.ORG Delivered-To: freebsd-stable@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 45C5D16A421 for ; Thu, 24 May 2007 12:14:26 +0000 (UTC) (envelope-from matrix@itlegion.ru) Received: from corpmail.itlegion.ru (corpmail.itlegion.ru [84.21.226.211]) by mx1.freebsd.org (Postfix) with SMTP id 6E49C13C4DE for ; Thu, 24 May 2007 12:14:25 +0000 (UTC) (envelope-from matrix@itlegion.ru) Received: (qmail 19118 invoked from network); 24 May 2007 16:14:24 +0400 Received: from unknown (HELO Artem) (192.168.0.12) by 84.21.226.211 with SMTP; 24 May 2007 16:14:24 +0400 X-AntiVirus: Checked by Dr.Web [version: 4.33, engine: 4.33.5.10110, virus records: 203291, updated: 24.05.2007] Message-ID: <031101c79dfd$104c21a0$05000100@Artem> From: "Artem Kuchin" To: "Oliver Fromme" , References: <200705241136.l4OBaA9P092420@lurza.secnetix.de> Date: Thu, 24 May 2007 16:14:21 +0400 Organization: IT Legion MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.3028 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028 Cc: Subject: Re: How to test locale in C? All my tests fail. 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: Thu, 24 May 2007 12:14:26 -0000 Oliver Fromme wrote: > Artem Kuchin wrote: >> I have a very stupid problem. I cannot convert to upper >> or lower case using manually set locale (setlocale(..)). >> >> A very simple program: >> [...] >> printf("IS UPPER ?: %d\n",isupper('?')); >> printf("IS UPPER ?: %d\n",isupper('?')); >> printf("IS LOWER ?: %d\n",islower('?')); > That's a common pitfall. Chars are signed by default on > FreeBSD, and the isupper() etc. function take an int type > argument. That means that characters >= 128 end up as > negative numbers, so they fail all isupper() and islower() > checks, and toupper()/tolower() don't touch them at all. > > The solution is to typecast the constants to unsigned char > explicitly, like this: isupper((unsigned char) '?') etc. > Your program will work fine then. My stupid. I should've noticed that. Thank you very much! Issue closed. -- Regards, Artem