Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site pyuxv.UUCP Path: utzoo!watmath!clyde!burl!ulysses!gamma!pyuxww!pyuxv!cim2 From: cim2@pyuxv.UUCP (Robert L. Fair) Newsgroups: net.lang.c Subject: enums, pcc & all that Message-ID: <212@pyuxv.UUCP> Date: Mon, 16-Jun-86 23:45:38 EDT Article-I.D.: pyuxv.212 Posted: Mon Jun 16 23:45:38 1986 Date-Received: Wed, 18-Jun-86 04:15:55 EDT Organization: CHC Lines: 47 Several folk seemed to have missed the point in my recent posting on enums - A true enumerated type is a useful thing because it: * catches lots of silly bugs with constant values, especially with variables representing finite states in large applications. * makes the code more readable & maintainable, especially in the definitions section - all the possible value for a datatype are gathered togther, and clearly marked: enum { RUN, WAIT, SLEEP, READ, WRITE, SLUGS } state; or #define RUN 1 #define WAIT 2 #define SLEEP 3 #define READ 3 #define WRITE 5 #define SLUGS 6 int states; (yes - there is a bug in the #defines...) Unfortunatly those that be decided to do a STUPID, DUMB and and CRETINOUS implementation of enums as integers (from those that bring you unary+ ...) As to the comment on printf not being able to print enums, it can't print structures or unions either - so why worry! Remember that enums are usually used to represent states or control flow in a program - they aren't often printed out (except when debugging etc - and for that you can always give a regular message: enum { ALIVE, RUNNING, COLLAPSED } jogger; ... if(jogger==ALIVE) { #ifdef DEBUG printf("hey, he's alive\n"); #endif ... } or coerce to an int if need be.) For more general cases, use C++ ! The only compiler I know which does enums right is Microsoft 3.0 for the IBM-PC. Rob. Fair Bell Communications Research ihnp4!pyuxv!cim2