What $sformat()?

what is the functionality of $sformat() can u please explain about it?

Hi,

$sformat() update the string with value which you have passed to it.

string a;
$sformat(s," Hello world");

So here, “Hello world” will be stored in the string a.
It is as good as a = “Hello world”;

Hope this will help!!

Regards,

thank you very much vaibhav…
but in the following one what it mean?
$sformat(name,“slaves[%0d]”,i);

i think slaves[i] will be stored in name …
am i correct? if not please correct me.

thank you very much vaibhav

Hi murali,

You can observe the usage of $sformat by seeing the below example.

====================

xbus_slave_agent slave[2];

string instance_name;

for(int i=0; i < 2; i++)
begin
// string will be stored in the instance_name by replacing the %d with the value of i
$sformat(instance_name, “slave[%d]”, i);
slave[0] = xbus_slave::type_id::create(instance_name, this);
end

// Two slaves will be created with the instance names… slave[0], slave[1]

=============================

Thank you,
mpurna

$sformat(name,“slaves[%0d]”,i);

If i is 0, it will store the string “slaves[0]” in name.

$sformatf and $psprintf both could not be found in LRM, but could be found in user manual from Cadence. which says they are identical.

This is in 1800-2009, 21.3.3 Formatting data to a string

Gord