enums
David Keppel
pardo at june.cs.washington.edu
Sat Jul 30 03:01:34 AEST 1988
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: <your user name goes here>
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 at cs.washington.edu
{rutgers,cornell,ucsd,ubc-cs,tektronix}!uw-beaver!june!pardo
More information about the Comp.lang.c
mailing list