Question about toupper and tolower

Tom Clark tsclark at ihnp4.UUCP
Thu Nov 10 14:54:05 AEST 1983


John Rogers (fortune!jr) asked about tolower and toupper, and stated that in
System V (and version 7 and system III) tolower/toupper were defined as macros
in /usr/include/ctype.h.  Well, actually the macros defined in ctype.h are
called _tolower(c) and _toupper(c) and do indeed perform no checking.  The only
purpose of the ctype header file is to define character types (e.g. for running
C on a non-ASCII machine).  There are routines tolower(c) and toupper(c) in libc
which will do what you want (check case before conversion). The source is in
/usr/src/lib/libc/gen in tolower.c and toupper.c.  I can't speak for version 7
or system III, but suspect they do much the same thing.  You should also note
that the macros cannot be recoded to say:
#define tolower(c) (isupper(c) : _tolower(c) : c)
because this will result in c being evaluated more than once, which will
*definitely* break a lot of programs!
-- 
		Tom Clark, BTL IH, ihnp4!tsclark, (312) 979-2620



More information about the Comp.lang.c mailing list