# Value of member class are not updated

**URL:** <https://verificationacademy.com/forums/t/value-of-member-class-are-not-updated/32652>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, pass-argument-by-ref, systemverilog-Arrays\
**Created:** [December 15, 2016, 6:05am UTC](https://verificationacademy.com/forums/t/value-of-member-class-are-not-updated/32652 "2016-12-15T06:05:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![saritr](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/df705f/32.png) [@saritr](https://verificationacademy.com/forums/u/saritr)\
**Post date:** [December 15, 2016, 6:05am UTC](https://verificationacademy.com/forums/t/value-of-member-class-are-not-updated/32652/1 "2016-12-15T06:05:23Z")

</div>

I have the following base class:

```verilog
class base_transaction extends uvm_sequence_item();

   int rand_int_list [$];   
   bit rand_bit_list [$];

   
   bit [31:0] data [$];

   //uvm_object_utils\
   `uvm_object_utils(base_transaction)

   //constructor
   function new(string name = "base_transaction");
      super.new(name);
   endfunction: new

   //add to list functions
   function void add_rand_int(ref int mem);
      $display("array size is %d before push", rand_int_list.size());      
      rand_int_list.push_back(mem);
      $display("array size is %d after push", rand_int_list.size());
      //rand_int_list[rand_int_list.size()] = mem;
   endfunction: add_rand_int

   function void add_rand_bit(ref bit mem);
     // rand_bit_list.
      rand_bit_list[rand_bit_list.size()] = mem;      
   endfunction: add_rand_bit   
   

   //function my_randomize
   function int my_randomize(int seed);
      int temp, success;
      if (rand_int_list.size > 0)
	begin
	   for (int i = 0; i < rand_int_list.size(); i++)
	     begin
		// temp = $urandom_range(1,11);
		temp = (($urandom(seed)) + 1);
		rand_int_list[i] = temp - 1;
		success = (temp && success);
	     end
	   if(success == 0)
	     return 0;	   
	end
      if (rand_bit_list.size() > 0)
	begin
	   for (int i = 0; i < rand_bit_list.size(); i++)
	     begin
		// temp = $urandom_range(1,11);
		temp = (($urandom(seed)) + 1);
		rand_bit_list[i] = temp - 1;
		success = (temp && success);
	     end
	   if(success == 0)
	     return 0;
	   else
	     return 1;
	end
   endfunction: my_randomize
      
endclass: base_transaction

```

```verilog
I have the following class which extend the base class:
class tx_transaction extends base_transaction;
   bit [15:0] data_xi;
   bit [15:0] data_xq;
   int mem_int = 2, mem_int_a = 5; //TODO- delete

   //uvm_object_utils\
   `uvm_object_utils(tx_transaction)

   //constructor
   function new(string name = "tx_transaction");
      super.new(name);
   endfunction: new

   function void add_rand_macro();
      add_rand_int(mem_int);
      add_rand_int(mem_int_a);
   endfunction: add_rand_macro
   
   //TODO - DELETE
   function void foo();
      $display("rand mem int: %d %d", mem_int, mem_int_a);
   endfunction: foo

endclass: tx_transaction

```

I call the following function from the sequence (tx\_trx - is tx\_transaction instance, and i is iterator):

```verilog
	 tx_trx.add_rand_macro();
                 tx_trx.my_randomize(i+1);
	         tx_trx.foo();

```

For some reason the foo function display allwas 2 5 (memt\_int, mem\_int\_a), though those values are updated by the my\_randomize function (which random the array which the member class are passed by ref)

---

<div class="post-metadata">

**Author:** ![DigvijaysinhSuryavanshi](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/d/839c29/32.png) [@DigvijaysinhSuryavanshi](https://verificationacademy.com/forums/u/DigvijaysinhSuryavanshi)\
**Post date:** [December 15, 2016, 10:19am UTC](https://verificationacademy.com/forums/t/value-of-member-class-are-not-updated/32652/2 "2016-12-15T10:19:18Z")

</div>

_In reply to [saritr](https://verificationacademy.com/forums/t/value-of-member-class-are-not-updated/32652):_

Hi saritr,

Consider following sample example to understand issue.  
In your code “my\_randomize” operates on queue list ‘rand\_int\_list’ but not directly on passed ref arguments [mem\_int, mem\_int\_a].

If you want randomized values to get reflected inside your foo() method.  
Option1 : Perform randomization on class objects instead using queue of int/bit type.  
Option2 : Do randomization directly on [mem\_int, mem\_int\_a] variables instead  
storing them first in queue and then randomizing queue elements.

```auto
typedef class test_ext;
class tets_c;
  int a=6;  
  int int_q[$];
  test_ext test_q[$];  
    
  function add_int(ref int val);
    int_q.push_back(val);
  endfunction  
  function randomize_int();
     int_q[0]=$urandom_range(11,15);
  endfunction
  
  function add_obj(ref test_ext obj);
    test_q.push_back(obj);
  endfunction  
  function randomize_class();
    test_q[0].a=$urandom_range(21,25);
  endfunction 
endclass

class test_ext extends tets_c;
  function new() ;
    this.a=8;
  endfunction
  
  function foo();
    $display("int_q a %0d Actual a %0d",int_q[0], a);
    $display("test_q a %0d Actual a %0d",test_q[0].a,a);    
  endfunction  
endclass

  module m;
    test_ext t;    
    initial begin
      t=new();
      t.add_int(t.a);
      t.add_obj(t);
      t.foo();
      t.randomize_int();
      t.foo(); 
      t.randomize_class();
      t.foo();      
    end
  endmodule

```

---

<div class="post-metadata">

**Author:** ![saritr](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/df705f/32.png) [@saritr](https://verificationacademy.com/forums/u/saritr)\
**Post date:** [December 15, 2016, 12:03pm UTC](https://verificationacademy.com/forums/t/value-of-member-class-are-not-updated/32652/3 "2016-12-15T12:03:33Z")

</div>

_In reply to [DigvijayS](https://verificationacademy.com/forums/t/value-of-member-class-are-not-updated/32652/2):_

Hey DigvijayS,  
I can’t use this example because each transaction will have its own member.  
For example:

```verilog
class tx_transaction extends base_transaction;
   bit [15:0] data_xi;
   bit [15:0] data_xq;
   int mem_int = 2, mem_int_a = 5; //TODO- delete
   .....
endclass: tx_transaction

class rx_transaction extends base_transaction;
   bit [15:0] data_xi;
   bit xq;
   int delay =3, val = 5, num= 8; //TODO- delete
   .....
endclass: rx_transaction

```

---

<div class="post-metadata">

**Author:** ![DigvijaysinhSuryavanshi](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/d/839c29/32.png) [@DigvijaysinhSuryavanshi](https://verificationacademy.com/forums/u/DigvijaysinhSuryavanshi)\
**Post date:** [December 15, 2016, 12:29pm UTC](https://verificationacademy.com/forums/t/value-of-member-class-are-not-updated/32652/4 "2016-12-15T12:29:59Z")

</div>

_In reply to [saritr](https://verificationacademy.com/forums/t/value-of-member-class-are-not-updated/32652/3):_

Hi saritr,

Above example is for reference only to identify an issue.  
Preferred approach to solve this will be to use _**In-line constraints — randomize() with**_,a system verilog construct !!

---

<div class="post-metadata">

**Author:** ![saritr](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/df705f/32.png) [@saritr](https://verificationacademy.com/forums/u/saritr)\
**Post date:** [December 15, 2016, 1:54pm UTC](https://verificationacademy.com/forums/t/value-of-member-class-are-not-updated/32652/5 "2016-12-15T13:54:45Z")

</div>

_In reply to [DigvijayS](https://verificationacademy.com/forums/t/value-of-member-class-are-not-updated/32652/4):_

I can’t use In-line constraints — randomize() because I use modelSim.  
The question is if there is any way to get what I want - that “my\_randomize” operates on directly on passed ref arguments [mem\_int, mem\_int\_a]…

---

<div class="post-metadata">

**Author:** ![Chandra\_Bhushan\_Singh](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/c/73ab20/32.png) [@Chandra\_Bhushan\_Singh](https://verificationacademy.com/forums/u/Chandra_Bhushan_Singh)\
**Post date:** [December 22, 2016, 1:29pm UTC](https://verificationacademy.com/forums/t/value-of-member-class-are-not-updated/32652/6 "2016-12-22T13:29:04Z")

</div>

_In reply to [saritr](https://verificationacademy.com/forums/t/value-of-member-class-are-not-updated/32652/5):_

Saritr:

Pass by reference does not work like as you are trying to implement. Function add\_rand\_int(mem\_int); add\_rand\_int(mem\_int\_a); scope is completed when they return. Now in queue values which you store does not pointing to mem int and mem\_int\_a. You need to modify the function.
