How to write a system verilog function to swap two class objects using pass by reference?
Here is what I could come up with. Is there a better way?
How to write a system verilog function to swap two class objects using pass by reference?
Here is what I could come up with. Is there a better way?
In reply to hkc:
Why not declare the temp variable in the function?
In reply to hkc:
You code is illegal—you are not allowed have pass by reference arguments in functions/tasks with static lifetimes. This restriction is because you are allowed to hierarchically access static arguments from outside a task/function and they would have bad references if you tried accessing them before they were called.
You rarely need pass by reference arguments. You should use inout arguments instead which have fewer restrictions.
function void swap(inout packet a,b);
packet temp;
temp = a;
a = b;
b = temp;
endfunction