Understanding Automatic or Automatic Lifetime of Class objects - SV

Hi All,

cfg.get_ci_id("if_s");

I see in this my TB code. cfg is a env configuration class and get_ci_id is a function which returns return(ci_id) which is of type cip_client_f
However i don’t see an object of cip_client_f being declared in that function. we don’t need object ?


function get_ci_id (string ..)
cip_client_f ci_id;

..
..
return (ci_id)

In another piece of code not related to this function i see

function ref2sb (axi_txn tx);
sb_item sb;
....
...

sb.axi_trans = axi_response_transaction::type_id::create("axi_rsp_trans"); // Creating object 
...
...
...sb2ref.ap.write (sb);

My question is if we can use the concept of not creating an object of class within a function as those are automatically allocated when the task or function is being called why are we explicitly creating an object ?
When to create a object and when not to when in functions ?

In reply to xfinity:

Your function definitions seem odd. LRM Section 13.4.1 discusses return values and void functions:

A function should be defined as: function <return_type_or_void> <function_name>(<function_arguments>)

Without <return_type_or_void>, the return type is a single bit. A ‘void’ type means that the function won’t return a value.

A function will implicitly declare an internal variable named function_name of the type return_type.

You would need to show the exact code and explain the issue you are having.

In reply to cgales:

function cip_slave_e cip_cfg::get_id (string name);
cip_slave_e cip_id;

    case(name)
       "if_apu_s": cip_id = CIP_AXI;
        ...
        ..
    endcase

return(cip_id);
endfunction

Above code there is no object of cip_slave_e being created and being passed to cip_id is this valid ?

Any examples of when to pass objects as arguments to functions and when to pass handles

In reply to xfinity:

Based on the name, I’d guess that cip_slave_e is an enumerated typedef. Therefore, cip_id is a singular value variable which doesn’t need to be created or new’d like a class variable.

Any examples of when to pass objects as arguments to functions and when to pass handles ?