Path: utzoo!utgpu!attcan!uunet!convex!killer!osu-cis!tut.cis.ohio-state.edu!mailrus!cornell!uw-beaver!uw-june!pardo From: pardo@june.cs.washington.edu (David Keppel) Newsgroups: comp.lang.c Subject: Re: enums Message-ID: <5400@june.cs.washington.edu> Date: 29 Jul 88 17:01:34 GMT References: <1608@dataio.Data-IO.COM> <469@m3.mfci.UUCP> <1988Jul22.171612.6225@utzoo.uucp> <5447@ihlpf.ATT.COM> <31416@cca.CCA.COM> <8266@brl-smoke.ARPA> Reply-To: pardo@cs.washington.edu (David Keppel) Organization: U of Washington, Computer Science, Seattle Lines: 40 Disorganization: U of Washington, Computer Science, Seattle When you have an enum of the form: enum light_t { ON, OFF, FIZZLING }; it can be nice to be able to print the members. I've written a (completely gross hack) program that scans a .c or .h and produces a file with an extra .c tacked on the end (e.g., .c.c or .h.c) that contains static initializers like: char *light_t_s[] = { "ON", "OFF", "FIZZLING", 0 }; On newer compilers you can then get a printable string by saying something like: for( light=ON; light <= FIZZLING; ++light ){ printf( "light is %s..\n", light_t_s[light] ); } Unfortunately this won't work when you have particular values assigned to an enumerted type ( FOO=-1, BAR=0, BORK=1 ). If you're on the DARPA net you can anonymous ftp from % ftp june.cs.washington.edu login: anonymous passwd: cd pub get enum.c Otherwise, send me e-mail and I'll send you a copy. There's no man page, and the code isn't of sufficient quality to post. Please keep me informed of changes... ;-D on ( A tool for all ages ) Pardo pardo@cs.washington.edu {rutgers,cornell,ucsd,ubc-cs,tektronix}!uw-beaver!june!pardo