coding

ron minnich rminnich at lanl.gov
Tue Sep 2 15:14:01 CEST 2003


anybody object to anonymous enums? I've gotten used to them in Plan 9 and
like them. Instead of this:

#define FLOPPY_DEVICE   0
#define PARALLEL_DEVICE 1
#define COM2_DEVICE     2
#define COM1_DEVICE     3
#define SWC_DEVICE      4
#define MOUSE_DEVICE    5
#define KBC_DEVICE      6
#define GPIO_DEVICE     7
#define ACB_DEVICE      8
#define FSCM_DEVICE     9
#define WDT_DEVICE     10

you get this:
enum {
 FLOPPY_DEVICE=0,
 PARALLEL_DEVICE,
 COM2_DEVICE,    
 COM1_DEVICE,    
 SWC_DEVICE,     
 MOUSE_DEVICE,   
 KBC_DEVICE,     
 GPIO_DEVICE,    
 ACB_DEVICE,     
 FSCM_DEVICE,    
 WDT_DEVICE
};

The advantages I see
- somewhat less prone to error
- looks nicer
- the big one: enums are first-class objects to the compiler, and 
  #defines are pertty much ripped out by the compiler and disappear
  into constant numbers. 


comments?

ron




More information about the coreboot mailing list