Enums in packed data

Hi all,

I have few questions about enumerations in packed data:

According to the LRM, “only packed data types and the integer data types summarized in Table 6-8 (see 6.11) shall be legal in packed structures.” This means, no enumeration types are allowed in packed structs. Is this understanding correct?

On the other hand, “packed arrays can be made of only the single bit data types (bit, logic, reg), enumerated types, and
recursively other packed arrays and packed structures.”

This means, I could define a one-element packed array of an enumeration type and use this inside of a packed struct. Correct?

Could I then assign a logic value without converting it to the enumeration type?

typedef enum logic [2:0] {NOP = 3'b001, AND, OR, XNOR, NAND, XOR} op_t;

  typedef op_t [0:0] op_array_t;

  typedef struct packed {
    op_array_t op;
  } op_struct_t;

  op_array_t op_a;
  op_struct_t op_s;

  assign op_a =  3'b001;
  assign op_s =  3'b011;

Or is the usage of an enumeration element (including of an assignment pattern) mandatory?
Something like:

  assign op_a1 = '{NOP};
  assign op_s1 = '{op: '{OR}};

Thanks a lot,
Thomas

In reply to Thomas Kruse:

No. If you are referring to the text in 7.2.1 Packed structures, a enum has a base type that is a packed type, such as int.

And yes, there is a loophole in the strong typing if you declare an enum inside another packed type, you can assign it directly with an integral value.

In reply to dave_59:

Understood. Dave, thanks a lot again.

Best regards,
Thomas

In reply to dave_59:
Why I am getting error as “The expression ‘op_a’ is not an instance of an enum variable”,when i am using enum’s name method for printing enum.


module top;
    initial begin

  typedef enum logic [2:0] {NOP = 3'b001, AND, OR, XNOR, NAND, XOR} op_t;
 
  typedef op_t [0:0] op_array_t;
 
  typedef struct packed {
    op_array_t op;
  } op_struct_t;
 
  op_array_t op_a;
  op_struct_t op_s;
 
  op_a =  3'b100;
  op_s =  3'b011;
      $display("array is %p ",op_a);  //this is giving result as 'XNOR'
      $display("array is %p and %s ",op_a,op_a.name());  //getting error when using name method.

    end
endmodule

In reply to Yash_wanth12345:

Attaching link of edaplayground example :- Edit code - EDA Playground

In reply to Yash_wanth12345:

op_a is an array. So, an enum method will not work here.

It should be

$display("array is %p and %s ",op_a,op_a[0].name());

In reply to Thomas Kruse:
Oh hey,Thank you.