[sv-bc] Proposal for enum type checking (typo - resend)


Subject: [sv-bc] Proposal for enum type checking (typo - resend)
From: Dave Rich (David.Rich@synopsys.com)
Date: Mon Feb 03 2003 - 22:36:18 PST


Several people pointed out a typo in my first email. Corrected word is in BOLD.
..............................................................................

Here is the wording I believe we agreed to at today's conference call,
with some additional examples

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).
An assignment to an enum variable FROM an expression other than an enum
variable or identifier of the same type shall require a cast. Casting to
an enum type shall cause a conversion of the expression to its base type
without checking the validity of it value.

typedef enum {Red, Green, Blue} Colors;
typedef enum {Mo,Tu,We,Th,Fr,Sa,Su} Week;
Colors C;
Week W;
int I;

C = Colors'(C+1); // C is converted to an integer, then added to one,
then converted back to a Colors type
C = C + 1; C++; C+=2; C = I; // Illegal because they would all be
assignments of expressions without a cast
C = Colors'(Su); // Legal; puts an out of range value into C
I = C + W; // Legal; C and W are automatically cast to int

-- 
--
Dave Rich
Principal Engineer, CAE, VTG
Tel:  650-584-4026
Cell: 510-589-2625
DaveR@Synopsys.com



This archive was generated by hypermail 2b28 : Mon Feb 03 2003 - 22:37:18 PST