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

From Tom Lane
Subject Re: WIP: guc enums
Date
Msg-id 8857.1204696083@sss.pgh.pa.us
Whole thread Raw
In response to Re: WIP: guc enums  ("Heikki Linnakangas" <heikki@enterprisedb.com>)
Responses Re: WIP: guc enums
List pgsql-patches
"Heikki Linnakangas" <heikki@enterprisedb.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.)

            regards, tom lane

pgsql-patches by date:

Previous
From: Tom Lane
Date:
Subject: Re: libpq.so linking problem on Solaris using --with-gssapi
Next
From: Julius Stroffek
Date:
Subject: Sun Studio on Linux spinlock patch