From: | "Heikki Linnakangas" <heikki(at)enterprisedb(dot)com> |
---|---|
To: | "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | "Magnus Hagander" <magnus(at)hagander(dot)net>, "pgsql-patches" <pgsql-patches(at)postgresql(dot)org> |
Subject: | Re: WIP: guc enums |
Date: | 2008-03-05 09:42:28 |
Message-ID: | 47CE6B04.6020708@enterprisedb.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-patches |
Tom Lane wrote:
> "Heikki Linnakangas" <heikki(at)enterprisedb(dot)com> writes:
>> Magnus Hagander wrote:
>>> On my platform (linux x86) it works fine when I just cast this to (int *),
>>> but I'm unsure if that's going to be safe on other platforms. I had some
>>> indication that it's probably not?
>
>> No, I don't think that's safe. Some googleing (*) suggests that the
>> compiler is free to choose any integer type for an enum.
>
> Yeah, it's absolutely not safe.
>
> 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.
--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com
From | Date | Subject | |
---|---|---|---|
Next Message | Magnus Hagander | 2008-03-05 09:53:13 | Re: WIP: guc enums |
Previous Message | Julius Stroffek | 2008-03-05 08:48:58 | Sun Studio on Linux spinlock patch |