coding
Greg Watson
gwatson at lanl.gov
Tue Sep 2 15:40:01 CEST 2003
At 1:32 PM -0600 2/9/03, ron minnich wrote:
>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
I think they work well when you have a sequence of numbers like this,
but I would rather see each enum explicitly given it's value as in:
enum {
FLOPPY_DEVICE=0,
PARALLEL_DEVICE=1,
COM2_DEVICE=2,
COM1_DEVICE=3,
SWC_DEVICE=4,
MOUSE_DEVICE=5,
KBC_DEVICE=6,
GPIO_DEVICE=7,
ACB_DEVICE=8,
FSCM_DEVICE=9,
WDT_DEVICE=10
};
Otherwise you're forever trying to work out what the actual value is.
Where it doesn't work is when you have a bunch of random defines with
unrelated values, or values that jump about all over the place.
Greg
More information about the coreboot
mailing list