RE: [sv-bc] enumerated variable used with an equality operator

From: Arturo Salz <Arturo.Salz@synopsys.com>
Date: Tue Mar 25 2014 - 13:57:37 PDT
The distinction you make between relational and identity operators is a sensible one, but what's the difference between
  enum_var == number
And
  enum_var >= number && ! (enum_var > number)

It might seem weird to apply tighter type checking to one and not the other, right?

	Arturo

-----Original Message-----
From: owner-sv-bc@eda.org [mailto:owner-sv-bc@eda.org] On Behalf Of Steven Sharp
Sent: Tuesday, March 25, 2014 12:09 PM
To: Rich, Dave; Neil Korpusik; sv-bc@eda.org
Subject: RE: [sv-bc] enumerated variable used with an equality operator

By the way, == is not a relational operator.  The relational operators are defined in 11.4.4 and only include >, <, >= and <=.  So this text about type checking the relational operators doesn't actually apply to ==.

The author of this text probably intended it to apply to ==.  There are other places in the LRM that refer to relational operators and then explicitly mention ==, so this seems to be a common misuse of the term.

I think it makes less sense to apply type checking to the relational operators than to the equality operators.  The relational operators are clearly being applied to the numeric values of the enums, not the abstract values.  If the enum literals are defined with non-ascending values, the relational operators apply to the numeric values, not the order of the enum literals in the enum declaration.  But if the intent is just to avoid mistakenly comparing an enum to a literal of the wrong enum type, that applies pretty equally to both.  It would also apply to other operations that involve comparing values, such as the inside operator and case statements, but it is a much bigger stretch to try to claim that those are included in "relational operators".


-----Original Message-----
From: owner-sv-bc@eda.org [mailto:owner-sv-bc@eda.org] On Behalf Of Rich, Dave
Sent: Thursday, March 20, 2014 8:37 PM
To: Neil Korpusik; sv-bc@eda.org
Subject: RE: [sv-bc] enumerated variable used with an equality operator

It should be illegal, but it isn't

The LRM says:

Enumerated variables are type-checked in assignments, arguments, and relational operators. Enumerated variables are auto-cast into integral values, but assignment of arbitrary expressions to an enumerated variable requires an explicit cast.

The LRM does not explain what "type-checked" means, but I take it to mean if it can proceed to auto-cast it to an integral expression, it will. 

-----Original Message-----
From: owner-sv-bc@eda.org [mailto:owner-sv-bc@eda.org] On Behalf Of Neil Korpusik
Sent: Thursday, March 20, 2014 5:25 PM
To: sv-bc@eda.org
Subject: [sv-bc] enumerated variable used with an equality operator

Is the following legal? Should it be?

Neil



module top();

typedef enum {A,B,C,D} f_t;
typedef enum {X,Y,Z  } b_t;

initial begin
   f_t f;
   b_t b;

   f = A;
   if (f == X) $display("matched");   // legal?
end
endmodule

--
This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.


--
This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.



-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.



-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Received on Tue Mar 25 13:58:10 2014

This archive was generated by hypermail 2.1.8 : Tue Mar 25 2014 - 13:58:16 PDT