Casting int to string yields different results

In reply to rodrigoportella:

Your code has a few problems

  • It’s illegal to initialize a static variable in a procedural block without an explicit static keyword declaration. Or, if your intent was to have the variable initialized each time you enter the function, do something to make it have an automatic lifetime. See this link.
  • You are using $sformat() incorrectly. The second argument is supposed to be a formatting string. I believe you may have wanted to use
$sformat(myString, "%s", myInt);
  • It’s illegal to use the %h or %d format specifier on an argument that does not have an integral type. If you want to see the individual byte values of a string, do something like
typedef byte bytes_t[];
$displayh("myString = %p, myOtherString = %h", bytes_t'(myString), bytes_t'(myOtherString));