[Swan-dev] explicitly assigned enum values

Paul Wouters paul at nohats.ca
Wed Jul 16 04:27:01 EEST 2014


On Tue, 15 Jul 2014, D. Hugh Redelmeier wrote:

> One of the great things about enums (as opposed to #defines) is that the
> compiler will automatically assign values.
>
> Sometimes you don't want to leave the value assignment to the compiler.  A
> good example would be numbers assigned by IANA.
>
> Some of our enums in include/pluto_constants.h are explicitly assigned for
> no obvious reason.  I think we should undo this (or document why not).
>
>    kernel_interface
>    keyword_remotepeertype
>    keyword_xauthby

Fine with me.

> And another thing about enums.  It might be good, all other things
> being equal, to define a throw away first memver.  This will be assigned
> the value 0.  That way 0 won't be a legitimate value, and that is the
> most common value that would come up if a variable were not
> initialized.  A way to catch more errors.

That I don't like. Some code uses existence of an enum name as proof
some value is vaild, so made up values, even if 0, are a bad idea.

Paul



More information about the Swan-dev mailing list