Specman では、次のいずれかを使用して変数を文字列に変換できます。
x.to_string();
また
x.as_a(string);
両者に違いはありますか?そうでない場合、Specman が両方を提供するのはなぜですか?
Specman では、次のいずれかを使用して変数を文字列に変換できます。
x.to_string();
また
x.as_a(string);
両者に違いはありますか?そうでない場合、Specman が両方を提供するのはなぜですか?
as_a()
式を文字列だけでなく特定のタイプに変換できます。
list_of_int.as_a(string)
list_of_byte.as_a(string)
string.as_a(list of int)
string.as_a(list of byte)
bool = string.as_a(bool) (Only TRUE and FALSE can be converted to Boolean; all other strings return an error)
string = bool.as_a(string)
enum = string.as_a(enum)
string = enum.as_a(string)
を使用するas_a(string)
とto_string()
、常に同じ結果が得られるとは限りません。
var s: string;
s = "hello";
var lint: list of int;
lint = s.as_a(list of int);
print lint;
print lint.as_a(string);
print lint.to_string();
これにより、次のように出力されます。
lint =
104
101
108
108
111
lint.as_a(string) = "hello"
list.to_string() = "104 101 108 108 111"
これはto_string
、リストの各要素で実行され、リストがスペースで連結されるためですが、as_a
整数を文字に変換して連結し、hello
単語を提供します。