I’m trying to create an array of handles for a class, by randomize function I’ll get the “no of transactions”, this determines the no of handles to be created. for example : class_name obj_name[transactions]; is this right?
coz I’m getting a syntax error when I do this
dave_59
September 15, 2015, 5:23pm
2
In reply to Ammu4392 :
Can you please show some code, including the declarations of any variables reference by that code, and the actual error message.
bmorris
September 15, 2015, 7:55pm
3
In reply to Ammu4392 :
I believe you want something like…
classA obj[]; // dynamic array
...
virtual task body();
a.randomize();
num_txns = a.transactions;
obj=new[num_txns];
...
In reply to dave_59 :
virtual task body();
a.randomize();
txns = a.transactions;
classA obj[txns];
for(int i=0; i<txns; i=i+1)begin
`ovm_create(obj[ i])
a.randomize();
int x = a.core;
`ovm_send(obj[i])
wait(obj.rsp != null );
end
endtask : body
In reply to bmorris :
Yes. But does soemthing like that works?
In reply to Ammu4392 :
Can u also tel me how I’ll iterate through the array??
shud i use for loop or foreach?
bmorris
September 15, 2015, 8:26pm
7
In reply to Ammu4392 :
I’d use foreach for an array, but you can use both.
foreach (obj[i]) begin
…
end
In reply to bmorris :
Can u tel me why we are declaring the obj declaration outside of body?