Why can't we declare and assign a logic type in one step?

In reply to Shashank V M:

The difference is in the timing of of the assignment on the RHS.

When declaring a wire the RHS represent a continuous assignment.

wire y_and = a & b;
// above is a shortcut for below
wire y_and;
assign y_and = a & b;

But when declaring a variable, the RHS represent a procedural initialization assignment, and that assignment happens once at the begining of the life of that variable. For static variables, that happens once before time 0. For automatics, the assignment happens once when the entering the procedural block.

function automatic a();
  int x=0;
endfunction
// above is a shortcut for below
function automatic a();
  int x;
  x=0;
endfunction

1 Like