# SystemVerilog constraint: unique addr across array of structs without auxiliary array

**URL:** <https://verificationacademy.com/forums/t/systemverilog-constraint-unique-addr-across-array-of-structs-without-auxiliary-array/51514>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, constraint-randomization, unique\
**Created:** [January 4, 2026, 5:04am UTC](https://verificationacademy.com/forums/t/systemverilog-constraint-unique-addr-across-array-of-structs-without-auxiliary-array/51514 "2026-01-04T05:04:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tobias187](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/t/82dd89/32.png) [@Tobias187](https://verificationacademy.com/forums/u/Tobias187)\
**Post date:** [January 4, 2026, 5:04am UTC](https://verificationacademy.com/forums/t/systemverilog-constraint-unique-addr-across-array-of-structs-without-auxiliary-array/51514/1 "2026-01-04T05:04:30Z")

</div>

Hi Forum!  
Is it possible to constrain unique struct members in a dynamic array without a helper variable? (adr\_hlpr in this problem below) We can use 2 foreach loops but is that the only way?

```auto
typedef struct {
  rand bit[7:0] addr;
  rand bit[15:0] data;
}pkt_t;

class db;
  rand pkt_t pkt[];
  rand bit[7:0] adr_hlpr[];

  constraint c{
    pkt.size() == 10;
    adr_hlpr.size() == 10;
    unique {adr_hlpr};
    pkt.sum() with ((item.addr == adr_hlpr[item.index]) ? 1:0) == pkt.size();
  };
endclass: db

module tb_top();
  db db_h;

  initial begin
    db_h = new();
    db_h.randomize();

    $display("pkt : %p", db_h.pkt);
  end
endmodule: tb_top

```

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [January 5, 2026, 6:54pm UTC](https://verificationacademy.com/forums/t/systemverilog-constraint-unique-addr-across-array-of-structs-without-auxiliary-array/51514/2 "2026-01-05T18:54:11Z")

</div>

Why are you looking for another way?

---

<div class="post-metadata">

**Author:** ![arshi582](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/a/c77e96/32.png) [@arshi582](https://verificationacademy.com/forums/u/arshi582)\
**Post date:** [January 7, 2026, 4:54pm UTC](https://verificationacademy.com/forums/t/systemverilog-constraint-unique-addr-across-array-of-structs-without-auxiliary-array/51514/4 "2026-01-07T16:54:32Z")

</div>

Hi Dave,

On writing the unique constraint as `unique { pkt }` I observe compilation error.

> Invalid argument ‘this.pkt’ specified for ‘unique’ constraint

> Variable ‘pkt’ needs to be numeric for participating in a constraint expression.

**Seeking suggestions for the reason behind this error**

LRM 18.5.4 Uniqueness constraints says

> **The group of variables to be constrained shall be specified using a restricted form of the range\_list syntax in which each item in the comma-separated list shall be one of the following:**
> 
> **— A singular variable of integral or real type**
> 
> **— An unpacked array variable whose leaf element type is integral or real, or a slice of such an unpacked array variable**
> 
> **A leaf element of an unpacked array is found by descending through the array until an element is reached that is not of unpacked array type.**

Would leaf element of unpacked array ‘pkt’ be pkt\_t ( i.e structure type ) ?

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [January 9, 2026, 6:40am UTC](https://verificationacademy.com/forums/t/systemverilog-constraint-unique-addr-across-array-of-structs-without-auxiliary-array/51514/5 "2026-01-09T06:40:18Z")

</div>

Yes, the leaf elements of the unpacked array `pkt` are an unpacked struct. You could convert the leaf elements into a packed struct, but if your goal is to retain only the `addr` bits `unique`, this approach won’t give you the desired results.

You need to use the helper array and constrain the elements of the helper array to the `addr` field of the unpacked array

```
constraint helpme { foreach(adr_hlpr[i] ) adr_hlpr[i] == pkt[i].addr; }

```
