isalpha in ctype.h

Doug Gwyn gwyn at smoke.brl.mil
Thu Mar 21 07:39:39 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.
-The macro is:
-#define	_U	01
-#define	_L	02
-extern	char	_ctype_[];
-#define	isalpha(c)	((_ctype_+1)[c]&(_U|_L))
-It's the part (_ctype_+1)[c] i don't understand. Could there be any
-segmentation errors using this?

No, in fact that's a quite standard implementation of <ctype.h>.
The +1 is used to allow EOF (defined as -1) to also be used as the
argument to the is*() macros.
Note that some implementations will fail if fed arbitrary garbage
for arguments to the is*() macros, for example any integer value
more negative than -1.



More information about the Comp.lang.c mailing list