Hi, refer the sample code below,
I want to print a bunch of typecasted enum values, both name and number values.
It seems I must store the type casted value in some enum variable to be able to print it’s name value through %s or to use the .name() method.
I want to print lots of such values each with their own enum types. Declaring variables for each of their enum types is not practical.
I couldn’t find any online examples printing enum names without variables, so, I wanted to ask here, if there is a way to directly print the typecasted enums at all? Or I must use a variable?
Thanks in advance!
module temp();
typedef enum bit [1:0] {A = 0, B, C, D} testEnum;
logic [1:0] Var1 = '1;
//1
$display("%s(%h)", testEnum'(Var1), Var1); //prints <unknown character >(3)
//2
$display("%s(%h)", testEnum'(Var1).name(), Var1); //error at .name()
//3
testEnum Var1Enum = testEnum'(Var1);
$display("%s(%h)", Var1Enum, Var1Enum); //prints D(3) - ### ideal result ###
endmodule