2

I'm facing an compilation issues with sc_dt::sc_biguint data types. I tried to reproduce the issue with a simple example below

#include<iostream>
#include<systemc.h>
using namespace std;

template<typename DATA_TYPE>
class base {
    public:
    void fun(DATA_TYPE ind){
    }

    void fun(std::string name){
    }
};

int sc_main(int argc, char* argv[]){
    base<uint64_t> b1;
    b1.fun(0);
    b1.fun("a");

    base<sc_dt::sc_biguint<128>> b2;
    b2.fun(0);
    b2.fun("a");
    return 0;
}

Here the call to overloaded function fun() is compiling fine for b1 which is using uint64_t as template. Also if I use uin8_t, uint16_t it compiles fine. But as soon as I use systemc data types (e.g. sc_biguint data type), I get the compilation errors like following

../test.cpp: In function ‘int sc_main(int, char**)’:
../test.cpp:21:13: error: call of overloaded ‘fun(int)’ is ambiguous
     b2.fun(0);
             ^
../test.cpp:8:10: note: candidate: void base<DATA_TYPE>::fun(DATA_TYPE) [with DATA_TYPE = sc_dt::sc_biguint<128>]
     void fun(DATA_TYPE ind){
          ^~~
../test.cpp:11:10: note: candidate: void base<DATA_TYPE>::fun(std::__cxx11::string) [with DATA_TYPE = sc_dt::sc_biguint<128>; std::__cxx11::string = std::__cxx11::basic_string<char>]
     void fun(std::string name){
          ^~~
../test.cpp:22:15: error: call of overloaded ‘fun(const char [2])’ is ambiguous
     b2.fun("a");
               ^
../test.cpp:8:10: note: candidate: void base<DATA_TYPE>::fun(DATA_TYPE) [with DATA_TYPE = sc_dt::sc_biguint<128>]
     void fun(DATA_TYPE ind){
          ^~~
../test.cpp:11:10: note: candidate: void base<DATA_TYPE>::fun(std::__cxx11::string) [with DATA_TYPE = sc_dt::sc_biguint<128>; std::__cxx11::string = std::__cxx11::basic_string<char>]
     void fun(std::string name){
1
  • sc_dt::sc_biguint<128> has the implicit conversion constructor sc_biguint( const sc_bv_base& v ) and sc_bv_base has the implicit conversion constructor sc_bv_base( const char* a );. You are unlucky. Perhaps, you need to specialize template<size_t N> class base<sc_dt::sc_biguint<N>>. Commented Jan 3 at 19:23

1 Answer 1

2

The error message confirms an obvious problem in your program. For [DATA_TYPE = sc_dt::sc_biguint] the call to base::fun with raw character array input is ambiguous. Because apparently both std::string and sc_biguint have constructors accepting raw character arrays. Fixing that one is relatively simple: put in comstructed instances of either class:

using namespace std::literals;
b2.fun("a"s); /* UDL `s` is a shorthand for `std::string`*/
//shorten the typename first:
using bign128 = sc_dt::sc_biguint<128>;
b2.fun(bign128{"a"});

On the other hand, sc_biguint doesn't have any constructor that accepts an int as its input. And the sc_unsigned::sc_unsigned(int) is explicit. Its explicit instantiation must work:

b2.fun(sc_dt::sc_unsigned{0});

But this may not be what you expected from numeric comstant input. It looks to be preallocating some interal array to input size. A rational choice would be to default construct the big number; so it will automatically initialize to 0:

b2.fun(bign128{});

Always read the documentation and check the header file contents, before using any library. You may still be missing a lot of important stuff.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.