Question : What is the difference between task and function in SystemVerilog?
- Task can have time control statements and delay, while function doesn’t support time control statement.
- Function can have return value, but task cannot.
- Task can call other task/functions, but function cannot call a task. (This limitation is on Verilog, SystemVerilog allow function to call a task using spawned thread.)
- A function must have at least one input argument, while task can have no arguments at all.
- Both task and function support input, output, inout as their argument.
- For inout type, the argument act as input at the beginning and as output at the end of the routine.
- If a task that does not consume time, it is advisable to make it a void function, so it can be called from any task or function.