DragonFly BSD
DragonFly commits List (threaded) for 2005-07
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: cvs commit: src/include ctype.h src/lib/libc/gen isctype.c tolower.c toupper.c


From: Matthew Dillon <dillon@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 7 Jul 2005 10:25:58 -0700 (PDT)

:hm. this doesn't really add value to your testing case for passing signed
:chars. now they all appear non-printable - and not like the integer
:equivalent, as the naive programmer would expect. I would prefer the
:openbsd way:
:	if (c =3D=3D EOF)
:		return 0;
:	else
:		return ((table+1)[(unsigned char)c)]);
:
:this gives expected results for (common?) misuse and even saves us one
:conditional.
:
:cheers
:  simon

    Well, from all the standards that were quoted at me I don't think 
    we can safely return anything but 0 for negative numbers simply 
    because the data space for one of those numbers, -1, is overloaded.
    Since there is no way to get around the the -1 vs 0xFF problem, it's
    probably best not to try to retain compatibility for other 
    negative numbers either.

    Another possibility would be to use more GCC constructs to check
    whether the passed type is a char and emit an #error if it is
    (verses just emitting a warning which is useless relative to
    all the warnings we get compiling third party software anyway).
    But I dislike such a solution because a program could use char's
    to store restricted ascii characters and still be entirely
    correct.

    So I think its best to stick with just returning 0 for
    out of bounds values.

						-Matt



[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]