isalpha in ctype.h

Adrian Collins collinsa at p4.cs.man.ac.uk
Fri Mar 22 23:05:14 AEST 1991


In <1991Mar20.112543.5515 at ericsson.se> etxnisj at eos8c21.ericsson.se (Niklas Sjovall) writes:

>Hi,

>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?

>From what I gather _ctype_[] is an array (probably 256 bytes) in length, 
each character has a corresponding entry into the table which contains
information about the type characters suchas if it is printable,
is whitespace, is uppercase, is lowercase.

In the example about it checks to see if the bits corresponding to
either uppercase or lowercase are set.  If either is set then the
character is an alphabetic character.

For some reason the first entry in the array isn't used for holding
character type information (beats me why), in which case the array is
probably 257 in length presuming it isn't null terminated.

Adrian

---
Adrian Collins                              collinsa at uk.ac.man.cs.p4
Department of Computer Science              a.m.collins at uk.ac.mcc
University of Manchester
Manchester,                                 "Let me face the peril"
UK.                                         "No, it's too perilous!"
                                                    - The Holy Grale



More information about the Comp.lang.c mailing list