Hi
I got the following error, but I don’t how to fix it, please help! Thanks
error message:
xrun: 20.09-s003: (c) Copyright 1995-2020 Cadence Design Systems, Inc.
twosum(nums,9,x[$]);
|
xmvlog: *E,TYCMPAT (testbench.sv,21|18): formal and actual do not have assignment compatible data types (expecting datatype compatible with ‘int’ but found ‘queue of int’ instead).
xmvlog: *W,NOTOPL: no top-level unit found, must have recursive instances.
xrun: *E,VLGERR: An error occurred during parsing. Review the log file for errors with the code *E and fix those identified problems to proceed. Exiting with code (status 1).
TOOL: xrun 20.09-s003: Exiting on Dec 25, 2020 at 02:57:41 EST (total: 00:00:00)
my code:
module tb;
int x[$];
task twosum(input int nums[$],target,output int a[$]);
foreach(nums[i]) begin
for(int j=i+1;j<nums.size();j++)begin
if(nums[i]+nums[j]==target)begin
a=a.push_back[i];
a=a.push_back[j];
end
end
end
endtask
initial begin
static int nums[$] ={2,7,11,15};
int x[$];
twosum(nums,9,x[$]);
$display("dispaly:index:%d",x);
end
endmodule
In reply to lucky002:
Hi,
While making the call to the task ‘twosum’, you can simply pass ‘x’ as the argument. No need to use [$]. Please try this.
Hope this helps.
Putta Satish
Thanks for helping me solve the problem!
but when I just call the task twosum(nums,9,x); it cause more error,like following:
xmelab: *E,FNTTSK (./testbench.sv,11|22): Expecting a function name.
a=a.push_back[i];
|
xmelab: *E,FAABP1 (./testbench.sv,11|22): Task/function call, or property/sequence instance does not specify all required formal arguments.
a=a.push_back[i];
|
xmelab: *E,BIMFOR (./testbench.sv,11|22): The format for this built in method is: task void push_back(input element_t item);.
a=a.push_back[j];
|
xmelab: *E,FNTTSK (./testbench.sv,12|22): Expecting a function name.
a=a.push_back[j];
|
xmelab: *E,FAABP1 (./testbench.sv,12|22): Task/function call, or property/sequence instance does not specify all required formal arguments.
a=a.push_back[j];
|
xmelab: *E,BIMFOR (./testbench.sv,12|22): The format for this built in method is: task void push_back(input element_t item);.
xrun: *E,ELBERR: Error during elaboration (status 1), exiting.
TOOL: xrun 20.09-s003: Exiting on Dec 30, 2020 at 21:00:39 EST (total: 00:00:01)
Your code has many problems. The following compiles and runs, but I have no idea what you expect it to do.
module tb;
int x[$];
task twosum(input int nums[$],target,output int a[$]);
foreach(nums[i]) begin
for(int j=i+1;j<nums.size();j++)begin
if(nums[i]+nums[j]==target)begin
a.push_back(i); // compare this to what you wrote
a.push_back(j);
end
end
end
endtask
initial begin
static int nums[$] ={2,7,11,15};
int x[$];
twosum(nums,9,x); // x - is the entire array x[$] is the last element
$display("dispaly:index:%p",x); // need %p
end
endmodule