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 comment
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 comment
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 comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...