Jump to content
Dev

Casting in systemC

Recommended Posts

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.

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×