Systemverilog: enum inside class versus struct?

A

afd

Guest
If I declare an 'enum' within a class definition, I noticed I can
use the same enum literal-labels elsewhere in my code:

// silly example#1: compiles ok!
class blah
enum logic [1:0] { STATE1, STATE2, STATE3, STATE4 } my_enum;
endclass : blah

class blah2
enum logic [1:0] { STATE1, STATE2, STATE3, STATE4 } my_enum;
endclass : blah2

^^^ causes no problems. Compiles successfully.
But if I change this code to the below:

// silly example#2: Compile-time error :(
typedef struct packed {
enum logic [1:0] { STATE1, STATE2, STATE3, STATE4 } my_enum;
} my_struct_type1;

typedef struct packed {
enum logic [1:0] { STATE1, STATE2, STATE3, STATE4 } my_enum;
} my_struct_type2;

"ERROR: STATE1 already defined enum literal."
Am I missing something? Do classes have their own (private)
declaration-scope,
but structs/unions don't?
 
afd wrote:

Am I missing something? Do classes have their own (private)
declaration-scope,
but structs/unions don't?
Yes, I believe that this is the case. A class definition is
definitely
a scope, and I don't think a struct definition is.
 

Welcome to EDABoard.com

Sponsor

Back
Top