| View previous topic :: View next topic |
| Author |
Message |
sharanbr Senior


Joined: Sep 27, 2004 Posts: 194
|
Posted: Fri Sep 28, 2007 7:19 am Post subject: sv : associative array class as key |
|
|
Has anyone used ass array with class objects as the key. I get compilation error (line AssArr[x] is declared) when I try the following code ..
| Code: |
module AssClass ;
class x ;
endclass
integer AssArr[x];
initial
begin
x x_i1 ;
x x_i2 ;
x_i1 = new;
x_i2 = new;
AssArr[x_i1] = 20 ;
AssArr[x_i2] = 30 ;
end
endmodule
|
|
|
| Back to top |
|
 |
carolina Junior


Joined: Sep 03, 2007 Posts: 5 Location: Brazil
|
Posted: Fri Sep 28, 2007 8:50 am Post subject: |
|
|
Hi,
My name is Carolina and I'm a SystemVerilog beginner. I don't know if I had understand your code, but I will try to help you.
So, first you had define a class called x.. After, you try to create a Integer array called AssArr[] using x to represent the array size.
But, is possible to use a class to represent an integer value? |
|
| Back to top |
|
 |
avidane Senior


Joined: Feb 17, 2006 Posts: 34 Location: Jerusalem, Israel
|
Posted: Fri Sep 28, 2007 9:04 am Post subject: Your code is perfectly legal... |
|
|
Hi,
It compiles and runs perfectly on Questa 6.3...
Carolina: x is not representing the array size but the type of the index. This is an associative array, not an ordinary array.
Avidan Efody
Verilab
www.specman-verification.com |
|
| Back to top |
|
 |
carolina Junior


Joined: Sep 03, 2007 Posts: 5 Location: Brazil
|
Posted: Fri Sep 28, 2007 9:29 am Post subject: |
|
|
Hi Avidan,
Thank you for the replay.  |
|
| Back to top |
|
 |
sharanbr Senior


Joined: Sep 27, 2004 Posts: 194
|
Posted: Fri Sep 28, 2007 12:43 pm Post subject: |
|
|
Thanks Avidan,
I will give a try on questa and see what happens .. |
|
| Back to top |
|
 |
AKSI Junior


Joined: Aug 21, 2007 Posts: 7
|
Posted: Mon Oct 01, 2007 9:32 am Post subject: |
|
|
| I have some problems with associative arrays as well, but when I changed the "indexing type" to wildcard (*), I no longer got the error and it's running fine. As long as your indexing type is integral, using wildcard is one way to bypass the error (although this would be the laziest way to do things). |
|
| Back to top |
|
 |
dave_59 Senior


Joined: Jun 22, 2004 Posts: 974 Location: Fremont, CA
|
Posted: Mon Oct 01, 2007 12:33 pm Post subject: |
|
|
| AKSI wrote: | | I have some problems with associative arrays as well, but when I changed the "indexing type" to wildcard (*), I no longer got the error and it's running fine. As long as your indexing type is integral, using wildcard is one way to bypass the error (although this would be the laziest way to do things). |
I strongly do not recommend ever using the wildcard index type. Use an integral type large enough to hold whatever value you expect to use an an index. The problem with the wildcard index type is that you can't use other features like foreach or the find() methods because the the wildcard index does not have a fixed type. (This is being clarified in P1800-2008)
Dave |
|
| Back to top |
|
 |
AKSI Junior


Joined: Aug 21, 2007 Posts: 7
|
Posted: Mon Oct 01, 2007 1:00 pm Post subject: |
|
|
| dave_59 wrote: | I strongly do not recommend ever using the wildcard index type. Use an integral type large enough to hold whatever value you expect to use an an index. The problem with the wildcard index type is that you can't use other features like foreach or the find() methods because the the wildcard index does not have a fixed type. (This is being clarified in P1800-2008)
Dave |
Thanks for the tip~ |
|
| Back to top |
|
 |
sraman Newbie


Joined: Mar 22, 2005 Posts: 1
|
Posted: Tue Nov 29, 2011 6:40 pm Post subject: |
|
|
Hi Dave,
I was able to use foreach and find in assoc array.
can you pls. clarify what do you mean by "you can't use other features like foreach or the find() methods because the the wildcard index does not have a fixed type."
Thanks,
Sathya |
|
| Back to top |
|
 |
dave_59 Senior


Joined: Jun 22, 2004 Posts: 974 Location: Fremont, CA
|
Posted: Wed Nov 30, 2011 1:18 pm Post subject: |
|
|
The following code is illegal as defined by the 1800-2009 LRM. | Code: | module top;
bit list[*];
bit [8*23:1] line1 = "a line of 23 characters";
bit [8*29:1] line2 = "another line of 29 characters";
bit [8*31:1] line3;
initial begin
list[line1] = 1;
list[line2] = 1;
foreach(list[line]) // What is the data type of line????
begin
line3 = {"\"",line,"\""};
$display("%s",line3);
end
end
endmodule
|
|
|
| Back to top |
|
 |
|