Is there a good example of how toupper() works?

Karl-P. Huestegge karl at robot.in-berlin.de
Wed Nov 7 15:37:05 AEST 1990


asylvain at felix.UUCP (Alvin "the Chipmunk" Sylvain) writes:

>In fact, defining this macro is *dangerous*.  Using a locally defined
>"toupper" routine from the standard <ctype.h> *guarantees* that the local
>hardware has been taken into account.  Furthermore, this is one more thing
>you don't have to debug.  Have you tested that macro over the entire ASCII
>character set?  Checked 'a', '`', '@', 'A', 'Z', '[', 'z', '{', etc.?
>(boundary checks)

>Conclusion: If there is a standard routine that does what you want, *use it*.
>This increases reliability and portability and reduces debug time.  If you're
>not sure what the routine does, RTFM and/or get help.  If you not sure that
>something you want to do has already been done, ask someone.  Good chance
>it's already been done.

Sorry, I missed the starting point of the discussion.

There is another reason to use the standard library functions:
The international Charactersets (8bit, ISO-8859-1 for example). On my
international development system toupper('a-umlaut') is ('A-umlaut'),
which is of course *not* 'a-umlaut'-32 or ('a-umlaut' - 'a'-'A').
The functions accesses a library of the local language-set (depending
on the environment-var LC_CTYPE)

One additional advice: Please don't use isascii() in text-functions,
because this forbits all international chars > 127. Use isprint()
instead (or whatever is appropriate).
Please keep your code 8-bit clean. Thousands of Users thank you.
(all the Renes, Angeliques, Mullers and Angstroms would be happy ;-).


-- 
Karl-Peter Huestegge                       karl at robot.in-berlin.de
Berlin Friedenau                           ..unido!fub!geminix!robot!karl



More information about the Comp.lang.c mailing list