isalpha in ctype.h

Richard A. O'Keefe ok at goanna.cs.rmit.oz.au
Thu Mar 21 14:04:03 AEST 1991


In article <1991Mar20.112543.5515 at ericsson.se>, etxnisj at eos8c21.ericsson.se (Niklas Sjovall) writes:
> I want to use a macro defined in ctype.h on a Sun4 (4.03), but i don't
> fully understand it.

You should read the manual page.  That tells you everything you need to
know in order to USE the macro.  In UNIX, it used to be the case that
the <ctype.h> macros were defined for EOF (-1) and for the integers
which satisfy isascii().  In ANSI C, the macros are defined for EOF
and for any value representable as unsigned char.  Think -1..255.

> It's the part (_ctype_+1)[c] i don't understand. Could there be any
> segmentation errors using this?

(_ctype_+1)[c] is identical to *((_ctype_+1)+(c)) which is
identical to _ctype_[(c)+1].  The +1 is there to map the lowest
legal value EOF (-1) to 0 (the lowest element of the array).
If you had full sources you'd probably find char _ctype_[257];
somewhere.

Yes, of course there can be segmentation errors using this,
if the value of c is outside the range -1 .. UCHAR_MAX, but
you have to keep your subscripts in range for _any_ C array.
-- 
Seen from an MVS perspective, UNIX and MS-DOS are hard to tell apart.



More information about the Comp.lang.c mailing list