# How to pass instance number in interface

**URL:** <https://verificationacademy.com/forums/t/how-to-pass-instance-number-in-interface/41913>\
**Category:** SystemVerilog\
**Tags:** System-verilog-interface, SystemVerilog, SystemVerilog-generate-assign\
**Created:** [July 10, 2023, 12:39pm UTC](https://verificationacademy.com/forums/t/how-to-pass-instance-number-in-interface/41913 "2023-07-10T12:39:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![PrashantSoni](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/p/848f3c/32.png) [@PrashantSoni](https://verificationacademy.com/forums/u/PrashantSoni)\
**Post date:** [July 10, 2023, 12:39pm UTC](https://verificationacademy.com/forums/t/how-to-pass-instance-number-in-interface/41913/1 "2023-07-10T12:39:51Z")

</div>

HI All,

I am traying to pass interface instance in interface but getting “Illegal Operand for constant expressions” error in wait statement .

```verilog

interface top_if();
  //Logics
  verif_if ve_intf[2]();
  chk_intf ck_intf[2]();

  genvar k;
  generate
    for(k=0;k < 2 ; k++) begin 
      ve_intf[k].instance_num = k;
    end
  endgenerate
endinterface 

interface verif_if ();
  //signals declaration
  int instance_num ;

  //trying to access signals of chk_intf
  initial begin 
    wait(ck_intf[instance_num].train_en[31:0] == 5); //Getting error "Illegal Operand for constant expressions [4(IEEE)]"
    $display("Training has been started");
  end 
endinterface

interface chk_intf();
  //signals declaration
  bit[31:0] train_en; //Its connected to design 
endinterface 

```

Here,If I take single instance of chk\_intf then I am not getting any error its working fine .  
Hence,I need your help to fix this issue .

---

<div class="post-metadata">

**Author:** ![cgales](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/c/ccd318/32.png) [@cgales](https://verificationacademy.com/forums/u/cgales)\
**Post date:** [July 10, 2023, 1:20pm UTC](https://verificationacademy.com/forums/t/how-to-pass-instance-number-in-interface/41913/2 "2023-07-10T13:20:20Z")

</div>

_In reply to [Prashant Soni](https://verificationacademy.com/forums/t/how-to-pass-instance-number-in-interface/41913):_

Your code as written doesn’t compile in any of the four simulators on EDA Playground. Specifically, the arrays of verif\_if and chk\_intf in top\_if are incorrect as they should be arrays of instances, which is not what is written.

I recommend using a parameter to verif\_if to specify the instance\_num instead of an int, as a parameter is a constant while a variable is not.

---

<div class="post-metadata">

**Author:** ![gengfei87](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/g/91b2a8/32.png) [@gengfei87](https://verificationacademy.com/forums/u/gengfei87)\
**Post date:** [July 11, 2023, 1:06am UTC](https://verificationacademy.com/forums/t/how-to-pass-instance-number-in-interface/41913/3 "2023-07-11T01:06:32Z")

</div>

_In reply to [cgales](https://verificationacademy.com/forums/t/how-to-pass-instance-number-in-interface/41913/2):_

Agreed, you can use parameters to do this.

---

<div class="post-metadata">

**Author:** ![PrashantSoni](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/p/848f3c/32.png) [@PrashantSoni](https://verificationacademy.com/forums/u/PrashantSoni)\
**Post date:** [July 11, 2023, 6:14am UTC](https://verificationacademy.com/forums/t/how-to-pass-instance-number-in-interface/41913/4 "2023-07-11T06:14:05Z")

</div>

Hi ,

Is there any other way to do it ? (like ref ,etc)

I will be able to do it by parameter but I will have to modify interface definition for every project and many files where I am getting this interface.

Because ,Its working fine with one instance of ck\_intf interface.

Thanks,  
Prashant.

---

<div class="post-metadata">

**Author:** ![cgales](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/c/ccd318/32.png) [@cgales](https://verificationacademy.com/forums/u/cgales)\
**Post date:** [July 11, 2023, 12:59pm UTC](https://verificationacademy.com/forums/t/how-to-pass-instance-number-in-interface/41913/5 "2023-07-11T12:59:32Z")

</div>

_In reply to [Prashant Soni](https://verificationacademy.com/forums/t/how-to-pass-instance-number-in-interface/41913/4):_

Interface instances are considered hardware constructs (with the exception of virtual interface handles), so you can’t use variables to index within an array of interfaces. During elaboration, the indexes need to be constant, hence why you can’t use a variable.

It works when you have a single interface since it is a constant reference.

Using a parameter will only affect the interface definition, and only in projects with this specific use case.

```verilog

interface top_if();
  //Logics
  chk_intf ck_intf[2]();
 
  genvar k;
  generate
    for(k=0;k < 2 ; k++) begin : verif_intf_inst
      verif_if#(.INSTANCE_NUM(k)) ve_intf ();
    end
  endgenerate
endinterface 
 
interface verif_if ();
  parameter int INSTANCE_NUM;
 
  //trying to access signals of chk_intf
  initial begin 
    wait(ck_intf[INSTANCE_NUM].train_en[31:0] == 5); //Getting error "Illegal Operand for constant expressions [4(IEEE)]"
    $display("Training has been started");
  end 
endinterface

```
