Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!mcsun!ukc!mucs!p4.cs.man.ac.uk!collinsa From: collinsa@p4.cs.man.ac.uk (Adrian Collins) Newsgroups: comp.lang.c Subject: Re: isalpha in ctype.h Message-ID: Date: 22 Mar 91 13:05:14 GMT References: <1991Mar20.112543.5515@ericsson.se> Sender: news@cs.man.ac.uk Lines: 38 In <1991Mar20.112543.5515@ericsson.se> etxnisj@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@uk.ac.man.cs.p4 Department of Computer Science a.m.collins@uk.ac.mcc University of Manchester Manchester, "Let me face the peril" UK. "No, it's too perilous!" - The Holy Grale