delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1999/06/08/20:28:14

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
Sender: cygwin-owner AT sourceware DOT cygnus DOT com
Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com
From: "Peter Kabal" <kabal AT ece DOT mcgill DOT ca>
To: <cygwin AT sourceware DOT cygnus DOT com>
Subject: tolower function
Date: Tue, 8 Jun 1999 20:26:55 -0400
Message-ID: <001401beb20e$c71e4a90$e145ce84@ECE.McGill.CA>
MIME-Version: 1.0
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook 8.5, Build 4.71.2173.0
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211
Importance: Normal

In an early version of a function to convert a string to lowercase, I did
not properly convert the input (signed) characters to unsigned before
handing them off to the tolower function.  I discovered that tolower behaves
oddly for negative input values.  For instance tolower(-32) returns zero,
while tolower(-31) returns -31.

Perhaps tolower should be fixed to behave "properly" for "improper" inputs.

-----------------------
Under cygwin B20.1, the test program which appears below prints out the
following.

0X64 (2:0) => 0X64
0X44 (0:1) => 0X64
0XFFFFFFE1 (0:0) => 0XFFFFFFE1
0XFFFFFFE0 (2:1) => 0X00
0XFFFFFFDF (0:1) => 0XFFFFFFFF

Running gcc on a Solaris system gives a different result.
0X64 (2:0) => 0X64
0X44 (0:1) => 0X64
0XFFFFFFE1 (2:0) => 0XFFFFFFE1
0XFFFFFFE0 (2:0) => 0XFFFFFFE0
0XFFFFFFDF (0:0) => 0XFFFFFFDF
(This one is suspicious, an seemingly innocuous change to print out the
first two values changed the third line islower value from 0 to 2!).

Finally running the Sun compiler on a Solaris system gives the following,
seemingly more reasonable result.
0X64 (2:0) => 0X64
0X44 (0:1) => 0X64
0XFFFFFFE1 (0:0) => 0XFFFFFFE1
0XFFFFFFE0 (0:0) => 0XFFFFFFE0
0XFFFFFFDF (0:0) => 0XFFFFFFDF

==============================
#include <ctype.h>
#include <stdio.h>

int main (int argc, const char argv[])
{
  int i;

  i = 'd';
  printf ("0X%.2X (%d:%d) => 0X%.2X\n", i, islower(i), isupper(i),
tolower(i));
  i = 'D';
  printf ("0X%.2X (%d:%d) => 0X%.2X\n", i, islower(i), isupper(i),
tolower(i));
  i = -31;
  printf ("0X%.2X (%d:%d) => 0X%.2X\n", i, islower(i), isupper(i),
tolower(i));
  i = -32;
  printf ("0X%.2X (%d:%d) => 0X%.2X\n", i, islower(i), isupper(i),
tolower(i));
  i = -33;
  printf ("0X%.2X (%d:%d) => 0X%.2X\n", i, islower(i), isupper(i),
tolower(i));

  return 0;
}


--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019