enum implementation

R.L.K.Dattatri rlkd at opusys.UUCP
Wed Jul 26 06:38:00 AEST 1989



	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          \    |__/        |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



More information about the Comp.lang.c mailing list