Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!sun-barr!cs.utexas.edu!uunet!opusys!rlkd From: rlkd@opusys.UUCP (R.L.K.Dattatri) Newsgroups: comp.lang.c Subject: enum implementation Keywords: enum, types, char/int Message-ID: <396@opusys.UUCP> Date: 25 Jul 89 20:38:00 GMT Organization: Opus Systems, Cupertino, CA Lines: 37 IMPLEMENTATION OF 'ENUM' in A COMPILER Recently, while using two different compilers I ran into a problem with the types if 'enum' constants. One of them treated the 'enum' constants as 'integer' and the other one stored them as 'single bytes'. So if I compile parts of a program with these compilers, the results are bad. This could also happen if a library is made with one compiler and the source that uses the library is from a different compiler. Question: What is the standard (ANSI) type of an 'enum' constant? The ANSI-C standard just says 'Each enumerated type shall be compatible with an integer type; the choice of type is implementation defined'. From K&R 'The identifiers in an enumerator list are declared as constants of type int and may appear wherever constants are required.' Some compilers determine the type based on the number of constants in the 'enum' type. Some compilers provide an option to set the enum constants to 'int's. So what is the correct way of implementing 'enum'. |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| | R.L.K. Dattatri (408) 446-2110 (W) |~~~~~| | | Opus Systems (408) 243-5140 (H) |_____| | | 20863 Bldg 400 |\ | |/ |~~\ | | Stevens Creek, Cupertino | \ [___|\ | | | | California, 95014 \ | | | | E-mail: uunet!opusys!rlkd FAX: (408) 446-5009 \ |__/ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~