Jump to content

Casting in systemC


Dev

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.

 

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

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.

Link to post
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...