How to write an 8-bit clean program

Karl Heuer karl at haddock.ima.isc.com
Thu Feb 15 09:42:50 AEST 1990


In article <1990Feb11.012110.2338 at utzoo.uucp> henry at utzoo.uucp (Henry Spencer) writes:
>Most of the time, cleanly-written code does not care.  Using chars as
>characters -- rather than small integers -- seldom runs into sign issues

The problem is that getc() and the <ctype.h> functions deal with a type which
should have been "char" but in fact is a certain subrange of "int", namely the
union of {EOF} and the values of "unsigned char".  Thus, even cleanly-written
code has to be sprinkled with casts to convert "plain char" to "unsigned char"
before handing it to "isprint()".  (I'm assuming ANSI C semantics here, so
there's no isascii() nonsense.)

Fixing this (by which I mean doing it *right*, not slapping on a backward-
compatible patch) would involve getting rid of the constant EOF entirely.  Of
course, it's too late to change it now.

Karl W. Z. Heuer (karl at ima.ima.isc.com or harvard!ima!karl), The Walking Lint



More information about the Comp.lang.c mailing list