Re: typedef enums are now unsigned?!
Re: typedef enums are now unsigned?!
- Subject: Re: typedef enums are now unsigned?!
- From: Clark Cox <email@hidden>
- Date: Sun, 8 Mar 2009 12:03:42 -0700
On Sun, Mar 8, 2009 at 10:36 AM, Darcy Brockbank <email@hidden> wrote:
>
> Clark Cox wrote:
>>
>> This is simply incorrect. From the C standard:
>>
>> "Each enumerated type shall be compatible with char, a signed integer
>> type, or an unsigned integer type. The choice of type is
>> implementation-defined,
>> but shall be capable of representing the values of all the members of the
>> enumeration."
>>
>> That is, the underlying type can be *any* integer type, not just int.
>
> You missed the relevant parts of the standard you're quoting. What you are
> referring to are the options available to the compiler after it has
> considered the
> enum in question.
>
> Valid values of the enum are explicitly stated in items (2) and (3) which
> are
> directly above item (4) which you are quoting. The relevant section is
> 6.7.2.2
> if anyone would like to read.
>
> Item (2):
>
> "The expression that defines the value of an enumeration constant shall be an
> integer
> constant expression that has a value representable as an int. "
>
> Note: *not* an unsigned integer, but an int. -1 is a valid choice in an
> enum.
>
> Item (3):
>
> "The identifiers in an enumerator list are declared as constants that have
> type int and
> may appear wherever such are permitted."
[snip]
The enumeration "constants" are of type int, the enumeration "type" is not.
>
> Note: enum type is "int". Period.
>
> The salient portion of Item (4) is:
>
> "The choice of type is implementation-defined, *****but***** shall be capable
> of
> representing the values of all the members of the enumeration."
If -1 is not a member, then this doesn't apply.
--
Clark S. Cox III
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden