Source File Organization

David F. Carlson dave at bigguy.ocpt.ccur.com
Tue Mar 19 02:52:08 AEST 1991


> Rick Farris writes:
> 
> > typedef enum { A, B, C, D } CMD;
> > 
> > and a corresponding array of ascii representations :
> > 
> > char ltrs[] = { 'A', 'B', 'C', 'D' };
> 

I would usually overload the operation for this using the initialization
property of enum types and the fact that they are defined to hold an
integer:

typedef enum { A = (int) 'A', B = (int) 'B', C = (int) 'C', D = (int) 'D'} CMD;

or if lexically ASCII is assumed,

typedef enum { A = (int) 'A', B, C, D } CMD;

Since B, C and D will be sequential, they will be correctly initialized.


Or is that cheating? :-)
-- 
David F. Carlson, Concurrent Computer Co.
dave at bigguy.ocpt.ccur.com       Fairport, NY

"The faster I go, the behinder I get." --Lewis Carroll



More information about the Comp.lang.c mailing list