Path: utzoo!attcan!uunet!midway!ncar!elroy.jpl.nasa.gov!usc!apple!agate!shelby!unix!hplabs!hpda!hpwala!hpavla!gary From: gary@hpavla.AVO.HP.COM (Gary Jackoway) Newsgroups: comp.lang.c Subject: Re: question about an array of enum Message-ID: <9130019@hpavla.AVO.HP.COM> Date: 5 Nov 90 13:43:22 GMT References: Organization: Hewlett-Packard Avondale Division Lines: 29 Henry Spencer writes: > In article it1@ra.MsState.Edu (Tim Tsai) writes: > >typedef enum {false, true} boolean; > > boolean bit_fields[1000]; > > > > How much memory does bit_fields actually take up, assuming a 32-bit > >architecture? Will my C compiler treat it as an array of int's? > Almost certainly it will treat it as an array of some integer type. > (ANSI C requires that, in fact.) The compiler is within its rights -------------------- > to treat it as an array of `int', although it could also be nice and > treat it as an array of `char' or some other small integer type. I don't think a compiler can make enums smaller than int and be ANSI compliant, since the standard says that enums are ints. Further, enums don't except the short/long keywords (at least not on MSC and HP-UX C). It is for this reason that I almost never use enums. Their size varies from machine to machine and there is nothing you can do about it. > If you really want the effect of an array of bits, you're going to have > to do the two-part addressing (get a byte/word and then pick out the bit > with a mask or a shift) yourself. Absolutely. Use macros to make it look like you are addressing an array of bits. Then, some day if the language supports this, you will be able to upgrade painlessly. Gary Jackoway