RE: [sv-bc] 4.10.4 "Enumerated types in numerical expressions" - unclearness

From: Bresticker, Shalom <shalom.bresticker_at_.....>
Date: Tue Nov 01 2005 - 01:35:07 PST
OK, I think I understand what you are saying.

The LRM says,
"An enum variable or identifier used as part of an expression is
automatically cast to the base type of the enum declaration (either
explicitly or using int as the default)."

You seem to be saying that, for example, in 4.10, where medal4 is
declared as "enum bit[3:0]", then if medal4 is used in an expression,
then it is cast to regular non-enum type "bit[3:0]".

I'll assume that interpretation.

But then, strictly speaking, the example at the bottom of p. 25 in
4.10.3, "c = green;" would mean that "green" would be cast to type int,
bringing us back to "c = 1;", which is illegal.

So I guess that case is to be excluded, and it should be interpreted to
mean an enum variable or enum identifier which is operated on by some
operator.

Now, is this any different from what 4.10.3 says,
"enumerated variables are auto-cast into integral values", or is it the
same idea written more fully?


Still unclear is the part about,
"(either explicitly or using int as the default)."

The intent seems to refer to the declaration of the enum base type
within the enum declaration.

However, the English grammar makes it seem mean,
"An enum variable or identifier used as part of an expression is
automatically cast, either explicitly or using int as the default, to
the base type of the enum declaration."

That is, it seems to refer to the automatic casting, which does not seem
to be the intent.

Thanks,
Shalom


>-----Original Message-----
>From: Steven Sharp [mailto:sharp@cadence.com]
>Sent: Tuesday, November 01, 2005 4:24 AM
>To: sv-bc@eda.org; Bresticker, Shalom
>Subject: Re: [sv-bc] 4.10.4 "Enumerated types in numerical
>expressions" - unclearness
>
>
>>From: "Bresticker, Shalom" <shalom.bresticker@intel.com>
>
>>This is confusing. Doesn't an enum variable already have the
>type of the
>>declaration by virtue of the declaration itself?
>
>Not quite.  While it is effectively a value of the base type
>for most
>purposes, it does have the additional property of being of the
>enum
>type also.  This makes it legal to assign to a variable of that
>enum
>type.  That would not be legal for a value of the base type
>that was
>not of that same enum type.
>
>Some of the confusion in the text comes from the strong-typing
>proponents
>trying to pretend like the enum isn't just an object of the
>base type
>with some extra type checking rules applied.  So the text talks
>about
>casting the enum to the base type, which is really a no-op;
>just ignoring
>the fact that it was officially an enum.  Another way of
>putting it would
>be to say that an expression operator applied to an enum
>behaves the same
>as applying it to an object of the base type, and the result is
>not an
>enum.  It is irrelevant whether you say that the enum gets cast
>to the
>base type and then the operator is applied, or that the
>operator is
>applied to the enum and the result of an operator is never an
>enum.
Received on Tue Nov 1 01:35:06 2005

This archive was generated by hypermail 2.1.8 : Tue Nov 01 2005 - 01:37:02 PST