coding
steven james
pyro at linuxlabs.com
Wed Sep 3 11:14:01 CEST 2003
Greetings,
It seems to me that working out the integer value of an enum is actually
abuse of the type. The closest one should get to that is ++ or -- to step
through enumerated objects.
Of course, nobody ever takes liberties with that, especially me :-)
If the value itself is significant, it should probably be a define. If
it's only significant for ABI compatibility, best practice is to only add
to the end of the list and retain deprecated enums until an ABI breaking
version change happens. A comma after the last enum value is a pretty
decent invitation to do the right thing.
G'day,
sjames
On Tue, 2 Sep 2003, Greg Watson wrote:
> 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
>
> _______________________________________________
> Linuxbios mailing list
> Linuxbios at clustermatic.org
> http://www.clustermatic.org/mailman/listinfo/linuxbios
>
--
-------------------------steven james, director of research, linux labs
... ........ ..... .... 230 peachtree st nw ste 2701
the original linux labs atlanta.ga.us 30303
-since 1995 http://www.linuxlabs.com
office 404.577.7747 fax 404.577.7743
-----------------------------------------------------------------------
More information about the coreboot
mailing list