tech-userlevel archive

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

Re: using the interfaces in ctype.h

On Mon, Apr 21, 2008 at 11:14:35AM -0400, Greg A. Woods; Planix, Inc. wrote:
>> Look closer.  The object indexed inside the macro is _one past_ the
>> base of the array object being indexed; this is done specifically to
>> support EOF as an argument.
> Nope, that does not work, at least not if the parameter is an int variable, 
> as would be compatible with the API specification, and as is most commonly 
> used in existing code in general I would guess.

Nonsense. The macros are effectively:
        isdigit(c) (int)(_ctype[(c) + 1] & N_)
etc. The way the offset is written makes it simpler for the compiler to
complain about the argument range. The 0 entry in all the tables is for

> A simple mask provides all of the safety one can hope for given the present 
> implementation.  :-)

A simple mask just hides the problem and makes it even worse. Now values
outside the allowed range will turn into silent wrong numbers. I've
heard at least one old age developer ranting about how it used to work
all the time because the FreeBSD definition *never* resulted in the
compiler warning.

This is absolutely the wrong approach to the problem. As soon as you
consider non-ASCII charsets, mapping EOF to 255 will return *wrong*


Home | Main Index | Thread Index | Old Index