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?
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?