0
\$\begingroup\$

Ran the following code on vcs :

module tb;
  reg [7:0] stack [2][4] ;
  initial begin

    foreach (stack[i])
    
    foreach (stack[i][j]) begin
  
      stack[i][j] = $random;
      
      $display("stack[%0d][%0d] = 0x%0h" , i, j, stack[i][j]);
      stack[1] = 0 ;
      
    end
    
    $display("stack = %p" , stack) ;
    
    $display("stack[1] = 0x%0h" , stack[1]);
  
  end

endmodule

The console gives the following errors:

Error-[ICTA] Incompatible complex type
design.sv, 15
  Incompatible complex type assignment
  Type of source expression is incompatible with type of target expression. 

  Mismatching types cannot be used in assignments, initializations and 
  instantiations. The type of the target is 'reg$[0:3]', while the type of the
  source is 'int'.
  Source Expression: 0
  

2 errors
  1. Is the assignment stack[1] = 0 ; valid?

  2. while the type of the source is 'int'. I don't really understand this error.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

No, the assignment is not valid. That is what the error message is telling you.

The RHS is an int: 0.

The LHS is an array of 4 elements: 0:3.

You declared stack as a 2D array. To assign a single number to one element, you need to specify both indexes, like you do in your 1st assignment: stack[i][j].

Or, if you want to assign 4 elements at once, use an assignment pattern:

      stack[1] = '{5, 6, 7, 8};
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.