[Bf-committers] Problem with UI colors, second attempt

Daniel Fairhead madprof at uk2.net
Fri Dec 3 09:47:16 CET 2004


> > You don't need to resert to #defines, which cannot be type-checked
> > by the compiler.  You can assign arbitrary values in an enumeration.
> >
> > e.g.
> > enum foo {
> > 	foo_jack=10,
> > 	foo_jill,
> > 	foo_hill,
> > 	foo_crown,
> > 	foo_bottom=100
> > };
> >
> 
> Wow, I should really read K&R more thoroughly once :)


What is also cool (appologies for the awful variable names):

#define CURRENTNUM 100

enum oz {
    sweet=CURRENTNUM,
    bilabong,
    bruce,
    sheila,
    bonza
};

#undef CURRENTNUM
#define CURRENTNUM roo

enum scots {
    wee=CURRENTNUM,
    loch,
    galoot,
    spangle,
    grand
};

#undef CURRENTNUM
#define CURRENTNUM grand

so you can add in extra elements anywhere you want, and all the other numbers shuffle about to make room. Death to hardcoded numbers! :-)

Dan


More information about the Bf-committers mailing list