次の SystemC コードを検討してください。
#include <iostream>
#include "systemc.h"
using namespace std;
int
sc_main(int argc, char* argv[])
{
sc_bv<3> foo;
operand_0 = "0d6";
cout << foo.to_long() << endl; // prints -2
return EXIT_SUCCESS;
}
これは、予想どおり 6 ではなく -2 を出力します。そうする明らかな理由は、to_long() がビットベクトル 0b110 を符号付きとして解釈することです。ただし、IEEE Std 1666-2011では、セクション 7.2.9 で to_long() などの整数変換関数について言及しています。
These member functions shall interpret the bits within a SystemC integer,
fixed-point type or vector, or any part-select or concatenation thereof,
as representing an unsigned binary value, with the exception of signed
integers and signed fixed-point types.
何か誤解しているのでしょうか、それとも Accellera の SystemC 実装がこの点で標準に準拠していないのでしょうか?