Dev Posted October 29, 2013 Report Share Posted October 29, 2013 hi all, I am just starting to do some practical implementations in systemC. Here i am trying to do a casting of data type ufixed to uint data type. i have tried the follwing code. #define SC_INCLUDE_FX #include "systemc.h" SC_MODULE(casting){ sc_in<sc_ufixed<8,8, SC_TRN, SC_SAT> > castin; sc_out<sc_uint<8> > castout; void do_cast(){ castout.write(castin.read()); // error in this line } SC_CTOR(casting){ SC_METHOD(do_cast); sensitive<< castin; } }; the problem is, it could not write the ufixed data type on uint type. So how should i do the casting between ufixed and uint data types. Is there any public methods available for this type of casting? or how should i proceed with it. Any ideas and help would be grateful for me. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
Philipp A Hartmann Posted October 29, 2013 Report Share Posted October 29, 2013 The implicit conversion between these types is not possible in all cases, mostly due to the danger of ambiguities in the API. Just add an explicit type conversion instead in terms of a C++ static_cast here: void do_cast(){ castout.write( static_cast<sc_uint<8> >(castin.read() ) ); } Greetings from Oldenburg, Philipp karandeep963 and Dev 2 Quote Link to comment Share on other sites More sharing options...
Dev Posted October 31, 2013 Author Report Share Posted October 31, 2013 Yes casting explicitly would be the perfect idea. Thanks for pointing it out. Quote Link to comment Share on other sites More sharing options...
dakupoto Posted November 1, 2013 Report Share Posted November 1, 2013 hi all, I am just starting to do some practical implementations in systemC. Here i am trying to do a casting of data type ufixed to uint data type. i have tried the follwing code. #define SC_INCLUDE_FX #include "systemc.h" SC_MODULE(casting){ sc_in<sc_ufixed<8,8, SC_TRN, SC_SAT> > castin; sc_out<sc_uint<8> > castout; void do_cast(){ castout.write(castin.read()); // error in this line } SC_CTOR(casting){ SC_METHOD(do_cast); sensitive<< castin; } }; the problem is, it could not write the ufixed data type on uint type. So how should i do the casting between ufixed and uint data types. Is there any public methods available for this type of casting? or how should i proceed with it. Any ideas and help would be grateful for me. Thanks in advance. Hello, In general, casting is an undesirable programming practice, as it forces the compiler to do things that it normally would not do. This is especially true for a strongly typed language as C++ (SystemC is after all C++). One should refrain from it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.