How to use toupper()

Ray Butterworth rbutterworth at watmath.waterloo.edu
Thu Jan 26 05:56:12 AEST 1989


In article <9457 at smoke.BRL.MIL>, gwyn at smoke.BRL.MIL (Doug Gwyn ) writes:
>     <ctype.h> macros should be made safe for "signed char"
>     arguments.
> The X3J11 response was:
>     The Committee has voted against this idea.
>     "char" arguments can always be cast to "unsigned char"
>     ... the argument *must* be cast to an "unsigned
>     char" for such implementations.

i.e. to write portable code, the user must put in lots of casts
rather than having the library do the messy stuff.
I thought the purpose of the Standard was to make writing portable
code easier.  Remember, the major argument people use for not
writing portable code is that it is too much trouble.  I really
can't see most people putting in these casts in the interest of
portability to other compilers or character sets.

> What's the point?  getchar() can return ANY byte value, or EOF.  The
> proposed Standard already requires that the argument to a ctype-
> function be representable as an "unsigned char" or equal the value EOF.
> 
> You've tried at least twice now to convince X3J11 to change this part
> of the specification, and you haven't convinced them.  Why carry on
> about it here?

Why?  Would you believe because I think I'm right and you are wrong.

But yes, I realize it is too late to change the Standard now.
On the other hand, there is no reason that library implementors
can't do it the "right" way, and with any luck the next version
of the Standard might go along with them.


A minor change in the wording of the standard would force a slight
change in the implementation, no change in efficiency, complete
compatibility with existing user code, and a vast improvement in
the programming environment provided by the language.

The minor change to the standard (i.e. valid input is EOF or the
low order byte of the argument),

would at worst require that the implementation increase the size
of the table used by macros by 50% (e.g. -128 to 255, plus EOF)

but would suddenly eliminate a lot of potential bugs and non-
portabilities in a lot of user code, and make it a lot simpler
for normal people to write portable programs without going to
any extra effort.  There would simply never be a need for anyone
ever to cast the arguments to the ctype functions for portability,
and the non-existence of isascii() would no longer be a problem.

Note that on most compilers EOF could still be defined as -1
(something that isn't required by the Standard anyway), since
none of the isxxx((unsigned char)'\377') functions are required
to return true for any of the existing compilers that use 7 bit
ASCII.




More information about the Comp.std.c mailing list