Xref: utzoo comp.lang.c:33472 comp.std.c:3887 Path: utzoo!attcan!uunet!jarthur!usc!zaphod.mps.ohio-state.edu!caen!umich!sharkey!rjf001!amara!mcdaniel From: mcdaniel@adi.com (Tim McDaniel) Newsgroups: comp.lang.c,comp.std.c Subject: Re: question about an array of enum Message-ID: Date: 6 Nov 90 16:45:04 GMT References: <9130019@hpavla.AVO.HP.COM> Sender: news@adi.COM Followup-To: comp.std.c Organization: Applied Dynamics International, Inc.; Ann Arbor, Michigan, USA Lines: 46 In-reply-to: gary@hpavla.AVO.HP.COM's message of 5 Nov 90 13:43:22 GMT gary@hpavla.AVO.HP.COM (Gary Jackoway) writes: > I don't think a compiler can make enums smaller than int and be ANSI > compliant, since the standard says that enums are ints. You're mixing 'enumeration constants' and 'enumerated types'. See Section 3.5.2.2 of the ANSI Standard. Enumeration constants (the identifiers between the { and the }) are of type 'int'. Then again, so are character constants, like '*'. "Each enumerated type shall be compatable with an integer type; the choice of type is implementation- defined." So the enum value itself might be a 'char', say, if the range of enumeration constants defined permits it. > 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. It is for this reason that I almost never use character constants like 'a'. They're ints, so their size varies from machine to machine and there is nothing you can do about it. What C type DOESN'T vary in size from machine to machine? (Answer: none. The Standard only sets minima, and in practice there is variation. I suspect that there are or will be compilers with 16 bit or 32 bit 'char'.) Why in creation you CARE how much space they take? I can see only two reasons: (1) binary files, (2) memory space. Binary files are inherently unportable. Often, worrying about memory space is worshipping the Little Tin God of Efficiency. If you have a large array AND have severely limited memory, you may need to worry. Otherwise, you may save a few bytes, but you may pay for it in slower access time. Only optimize if you absolutely need the space or the time, and then only attack the areas with the biggest payoffs until you fit into your budget. > Then, some day if the language supports [arrays of bits], you will > be able to upgrade painlessly. Can't happen. "sizeof (char) == 1" is now fixed in the language, as is the fact that it yields an integral type. -- Tim McDaniel Applied Dynamics Int'l.; Ann Arbor, Michigan, USA Work phone: +1 313 973 1300 Home phone: +1 313 677 4386 Internet: mcdaniel@adi.com UUCP: {uunet,sharkey}!amara!mcdaniel