question about an array of enum
Gary Jackoway
gary at hpavla.AVO.HP.COM
Tue Nov 6 00:43:22 AEST 1990
Henry Spencer writes:
> In article <it1.657622430 at ra> it1 at 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
More information about the Comp.lang.c
mailing list