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, 21 Apr 2008, der Mouse wrote:
> I don't think anyone has suggested application-level casting for cases
> where the argument might be EOF; that would be severely broken - which
> is why the implementation, which must be prepared to handle EOF
> arguments, should not do it (nor anything equivalent).


If you have an int which was returned by fgetc() or a function with a
similar interface, then it might be EOF, and you should not cast it in
any way before calling any of the ctype functions.

If you have a signed char (or a plain char, which might happen to be
signed, depending on the implementation), then you should cast it to
(unsigned char), or perhaps (int)(unsigned char), before calling any of
the ctype functions.

Advice very much like the above now appears in the ctype(3) man page.

Can anybody confirm the existence of compilers such that
this code:

        #include <ctype.h>
        int f(void)
            signed char c = -1;
            return isupper((unsigned char)c);

produces a warning which can be quieted by an additional cast to int,

        return isupper((int)(unsigned char)c);

?  If not, then I would like to change the ctype(3) man page back to
recommending just an (unsigned char) cast, not the (int)(unsigned char)
double cast.

--apb (Alan Barrett)

Home | Main Index | Thread Index | Old Index