Boolean datatypes (really about enum types and the PCC)

Donn Seeley donn at utah-gr.UUCP
Mon Jun 16 13:20:44 AEST 1986


I was informed by Rob Pike not too long ago that at least at the Labs,
enums are ints: enumeration constants are symbolic integer constants
and enumeration variables are simply ints.  Their compiler doesn't emit
any 'enumeration type clash' warnings and performs proper integer
operations on enums such as shifts (the BSD PCC won't permit shifts of
enum variables).  The proposed draft ANSI C standard doesn't seem to
require that compilers treat enums as anything other than ints.  If
people are writing programs which employ enums strictly as ints, the
utility of enums in type verification seems to be nil and compiler
warnings will just be obnoxious.

The situation with enums reflects the situation with typedefs in an odd
way -- despite appearances, neither construct defines a 'new' type.

As Guy Harris notes, enums are useful as replacements for preprocessor
constants and can serve as a debugging aid for programs like 'dbx'.
Given their limited application it's easy to see why they haven't
caught on.

Donn Seeley    University of Utah CS Dept    donn at utah-cs.arpa
40 46' 6"N 111 50' 34"W    (801) 581-5668    decvax!utah-cs!donn



More information about the Comp.lang.c mailing list