I have a struct with an unconstrained field and would like a function to return a value whose type is that struct, and where the unconstrained field is constrained by the size of the function input. I know how to do this in VHDL and was hoping there's a System Verilog equivalent. Here's my (very unsuccessful) first attempt at this:
typedef struct {
bit Vec [];
bit Parity;
} MyRec_t;
function automatic MyRec_t CreateMyRec (input Val []);
MyRec_t Rec;
Rec.Vec = new(Val.size()+4);
Rec.Vec = {4'hF,Val};
Rec.Parity = ^ Rec.Vec;
return Rec;
endfunction