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 22-Apr-08, at 3:51 AM, Alan Barrett wrote:
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,
thus:

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

?

Potentially some compiler might complain about the unsigned char to signed int promotion without the explicit (int) cast, though apparently GCC doesn't (at least not so long as UCHAR_MAX <= INT_MAX).

I'll try to get access to IRIX and Solaris machines again to try these. IIRC it was one of these I was seeing warnings from, and most likely it was IRIX, perhaps with whatever sensible warning options their compiler supports(*). Unfortunately that's the one I'm least likely to be able to get access to again so anyone else who has access to IRIX systems should try it.

(*) In Smail-3 I used the following on IRIX-6.x last time I tested it there:

        CFLAGS="-Xa -g3 -O3 -fullwarn -diag_suppress 1184,1209,3201,3496"
        LDFLAGS="-g3 -O3"


BTW, can anyone say with any degree of certainty which, if any, C implementations (hosted) will extend the sign when the value of a "char *" pointer is assigned to a plain "int"? I.e. in "int i = *s;"

DMR says (in the second edition of "The C Programming Language", p. 44): "On some machines a char whose leftmost bit is 1 will be converted to a negative integer ("sign extension")." In the first edition he also said "(PDP11, for instance)". Harbison and Steele, in "C A Reference Manual" say much the same too of course, though never in exactly the context of using the result of indirecting a "char *" pointer. DMR uses the "int c; char *s; while ((c = *s)) ..." idiom at least once (p.156), though perhaps that was a mistake.

--
                                        Greg A. Woods; Planix, Inc.
                                        <woods%planix.ca@localhost>



Home | Main Index | Thread Index | Old Index