Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!samsung!uakari.primate.wisc.edu!sdd.hp.com!elroy.jpl.nasa.gov!jato!mars.jpl.nasa.gov!kaleb From: kaleb@mars.jpl.nasa.gov (Kaleb Keithley) Newsgroups: comp.lang.c Subject: bitmask lookup table creation Message-ID: <3947@jato.Jpl.Nasa.Gov> Date: 6 Jun 90 00:00:21 GMT Sender: news@jato.Jpl.Nasa.Gov Reply-To: kaleb@mars.jpl.nasa.gov (Kaleb Keithley) Organization: Jet Propulsion Laboratory, Pasadena, CA. Lines: 27 I want to create the following bitmask lookup table: unsigned short masks[] = { 0x0000, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F, 0x003F, 0x007F, 0x00FF, 0x01FF, 0x03FF, 0x07FF, 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF }; in a machine independent way. In /usr/include/values.h, the following are #defined: #define BITS(type) (BITSPERBYTE * (int)sizeof(type) #define HIBITS ((short)(1 << BITS(short) - 1)) #define MAXSHORT ((short)~HIBITS) which are 0x8000 and 0x7FFF respectively on my machine, which happens to be a Sun Sparc. It is nearly trivial to do it at run-time, and the above definitely works on my Sun. Does anyone have any neat trick to generate this table at compile time in such a way as to be completely machine independent? adva-thanks-nce kaleb@thyme.jpl.nasa.gov Jet Propeller Labs Kaleb Keithley "So that's what an invisible barrier looks like"