Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!harpo!decvax!mcnc!ecsvax!bet From: bet@ecsvax.UUCP Newsgroups: net.unix-wizards Subject: Re: Ctype.h (start arrays at 1 then add 1 before looking up) Message-ID: <2189@ecsvax.UUCP> Date: Sun, 25-Mar-84 20:58:07 EST Article-I.D.: ecsvax.2189 Posted: Sun Mar 25 20:58:07 1984 Date-Received: Mon, 26-Mar-84 20:57:59 EST Lines: 24 In a lexical analyzer I wanted translate tables for values returned by getchar() -- including EOF (-1). I wanted them FAST. So I created arrays like this: struct { char dummy; char class[128]; } character= { /* list of 129 values for characters, starting with EOF */ }; My reasoning was as follows: members of a structure of homogeneous composition (no alignment problems) occupy consecutive locations in memory. C, god bless its black-hearted soul, doesn't attempt subscript bounds checking. Finally, character.class evaluates to a constant expression at compile time, which C compilers can (and my reading suggests they will) simplify at compile time. Therefore, I think I have a legal array with subscripts ranging from -1 to 127. Anything wrong with this? Shouldn't it be faster than always using array[i+1] (or evaluating i+1 into a temporary)? Inasmuch as I explained the trick clearly in a comment, I am not interested in arguments like "UGLY" or "confusing". Bennett Todd ...{decvax,ihnp4,akgua}!mcnc!ecsvax!bet