Packed structure radomization with constraints

Can I use packed structure in your example below and randomize?

Can you please point me to LRM section for this example?

typedef struct {
   rand int 	       data;
   rand int 	       data1;
} data_type;
 
class test;
 
   rand data_type m_data;
   constraint c_cons {
      m_data.data == 1;
      m_data.data1 == 2;
   }
endclass 

In reply to superUVM:

You cannot use rand on individual fields of a packed struct. (See 18.4 Random variables)

In reply to superUVM:

typedef struct {
int data;
int data1;
} data_type;

class test;

rand data_type m_data;
constraint c_cons {
m_data.data == 1;
m_data.data1 == 2;
}
endclass

Is this allowed?

In reply to superUVM:

What happened when you tried it?

In reply to dave_59:

It does randomize and constraints on individual fields are met.

In reply to superUVM:

Just want to make sure that is allowed and supported across all compilers.

In reply to superUVM:

It’s in the same section 18.4 I quoted above.

Can’t comment on support across all tools.

In reply to superUVM:

Struct “data_type” in the sample is “Unpacked Struct”, not “Packed Struct.”
That’s why, the sample works in all simulators.

It needs “packed” keyword to define packed struct, like

typedef struct packed {

} data_type