Re: WIP: guc enums

From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Heikki Linnakangas <heikki(at)enterprisedb(dot)com>, pgsql-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: WIP: guc enums
Date: 2008-03-05 15:20:27
Message-ID: 20080305152027.GS5559@svr2.hagander.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches

On Wed, Mar 05, 2008 at 08:18:19AM -0500, Tom Lane wrote:
> "Heikki Linnakangas" <heikki(at)enterprisedb(dot)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.

Looking for the two variables I've converted so far, there appears to be
zero places to make this change. They are only used in == and <= tests,
never in switches. Or should I add casts for those as well?

(I'm sure there can be other variables that are used in enums when I get
further down that list)

If we're good with that method, I'll proceed using that one. Any other
things people noticed with the patch that I should take into consideration
when I start my cleanup pass over the code?

//Magnus

In response to

Browse pgsql-patches by date

  From Date Subject
Next Message Bruce Momjian 2008-03-05 15:53:38 Re: [BUGS] BUG #3975: tsearch2 index should not bomb out of 1Mb limit
Previous Message Andrew Dunstan 2008-03-05 15:03:22 Re: WIP: guc enums