Re: WIP: guc enums - Mailing list pgsql-patches

From Tom Lane
Subject Re: WIP: guc enums
Date
Msg-id 21019.1204723099@sss.pgh.pa.us
Whole thread Raw
In response to Re: WIP: guc enums  ("Heikki Linnakangas" <heikki@enterprisedb.com>)
Responses Re: WIP: guc enums  ("Heikki Linnakangas" <heikki@enterprisedb.com>)
Re: WIP: guc enums  (Magnus Hagander <magnus@hagander.net>)
List pgsql-patches
"Heikki Linnakangas" <heikki@enterprisedb.com> writes:
> Tom Lane wrote:
>> What I'd suggest is declaring the actual variable as int.  You can still
>> use an enum typedef to declare the values, and just avert your eyes
>> when you have to cast the enum to int or vice versa.  (This is legal per
>> C spec, so you won't introduce any portability issues when you do it.)

> That's pretty much the same as int variable and #defined constants. You
> lose compiler checks, like assigning from one enum type to another, and
> the "enumeration value �FOOBAR� not handled in switch" warning.

Well, you can at least get the latter if you cast explicitly:

    switch ((MyEnum) myvariable) ...

We do this in several places already where the underlying variable isn't
declared as the enum for one reason or another.  Also, local variables
can be declared as the enum type to get a little more safety.

In any case, the alternative being suggested of keeping the variables as
strings throws away *every* possible code-level advantage of having an
enum variable classification.

            regards, tom lane

pgsql-patches by date:

Previous
From: Magnus Hagander
Date:
Subject: Re: WIP: guc enums
Next
From: "Heikki Linnakangas"
Date:
Subject: Re: WIP: guc enums