struct_union_member
::=
{ attribute_instance } data_type list_of_variable_identifiers_or_assignments variable_declaration ;
logic |
4-state
SystemVerilog data type, user-defined vector size |
SystemVerilog enumerated types are strongly typed, thus, a
variable of type enum
cannot
be directly assigned a value that lies outside the enumeration set unless an explicit cast is used, or unless
the enum
variable is a member of a union. This is a
powerful type-checking aid that prevents users from accidentally assigning
nonexistent values to variables of an enumerate type. This restriction only
applies to an enumeration that is explicitly declared as a type. The
enumeration values can still be used as constants in expressions, and the
results can be assigned to any variable of a compatible integral type.
3.10.4 Enumerated types in
comparison expressions
The result of any
operation on an enumeration variable after the variable has been assigned an
out of range value shall be undefined.
struct_union_member
::=
{ attribute_instance } data_type list_of_variable_identifiers_or_assignments variable_declaration ;
class_declaration ::=
{ attribute_instance } [ virtual ] class [ lifetime ] class_identifier [ parameter_port_list
]
[ extends class_identifier [parameter_value_assignment ] ]
; [ timeunits_declaration
]
{ class_item }
endclass [ : class_identifier]
This example assigns the expression (5 => black) to the enumerated type. Without $cast, or the static compile-time cast
described below, this type of assignment is illegal.