Re: nitpicking on strcasestr.c

From: Thomas Dickey <dickey_at_radix.net>
Date: Wed, 13 Oct 2004 08:50:26 -0400
On Wed, Oct 13, 2004 at 02:28:54PM +0200, Andrea Campi wrote:
 
> We have two calls to tolower(); the first doesn't cast the result
> at all, the second one casts it to char. Shouldn't the first one be
> changed also?

man tolower (Solaris - but if FreeBSD differs, someone has a problem):

NAME
     tolower - transliterate upper-case characters to lower-case

SYNOPSIS
     #include <ctype.h>

     int tolower(int c);
 
> Actually, my first feeling was to change both to unsigned char, but
> I'm sure somebody could go to great lenghts to explain to me how the
> code as it stands is carefully crafted to work whether chars are signed
> or unsigned....

Noting that tolower() returns an int, and char's sign is unspecified,
either changing the type for c (to int) or adding a cast is a good
idea.  Adding casts is generally a bad idea.

-- 
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net

Received on Wed Oct 13 2004 - 10:50:34 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:17 UTC