Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!dciem!nrcaer!cognos!jimp From: jimp@cognos.uucp (Jim Patterson) Newsgroups: comp.lang.c Subject: Re: Enum vs Define Message-ID: <1239@aldebaran.UUCP> Date: Tue, 11-Aug-87 10:23:35 EDT Article-I.D.: aldebara.1239 Posted: Tue Aug 11 10:23:35 1987 Date-Received: Fri, 14-Aug-87 03:26:55 EDT References: <19913@ucbvax.BERKELEY.EDU> Reply-To: jimp@cognos.UUCP (Jim Patterson) Organization: Cognos Inc., Ottawa, Canada Lines: 38 In article <19913@ucbvax.BERKELEY.EDU> oster@dewey.soe.berkeley.edu.UUCP (David Phillip Oster) writes: >in : > enum { > ERRMSGA = 1, > ERRMSGB = 2 > }; > ERRMSGA is defined to be a subtype of the smallest type that will >hold any of these enums. Since none of these enums are very large, >you'd expect: > >sizeof ERRMSGA == sizeof(char) I'm not familiar with any compiler that works this way. Apparently your LightSpeed compiler does; perhaps PC compilers are more space-conscious. Compilers I've used always make enum constants subtypes of a plain int. On the SUN, on VAX/VMS (using VAX-11 C) and on a DG MV system (AOS/VS C), enum constants all occupy 4 bytes, the same as int. This is in fact mandated by the current ANSI draft. In section 3.1.3.3 Enumeration Constants, it says "An identifier declared as an enumeration constant has type int". The compilers I've used have always made enum's (as opposed to enum constants) of int size as well. This is permissable but not required by the ANSI draft, which says (section 3.5.2.3 Enumeration Specifiers): "The implementation may use the set of values in the enumeration to determine whether to allocate less storage than an int". So, like normal integer constants, enum constants (like ERRMSGA) are required by the ANSI draft to be of size int. In this regard, it appears that your lightspeed compiler is non-compliant. Regarding the enumeration itself, the compiler is free to make it of size int, or to make it of a size less than an int but sufficient to contain all of its values. -- Jim Patterson decvax!utzoo!dciem!nrcaer!cognos!jimp Cognos Incorporated