Jump to content
HSDave

sc_signal & Operator

Recommended Posts

Hi,

 

I want to pass a sc_signal (the reference of one) of any type to a class as a CTOR-argument. Since i found out, that the &-Operator of the class sc_signal<T> is overloaded, so i don't get the reference of an sc_signal<T> object but instead i get a reference to an Object of type T.

How am i supposed to pass an sc_signal<T> to a function or a class?

 

Example-Code:

#include <systemc.h>

template<typename T>
class TInput{
public:
	typedef sc_signal<T> &TMember;
	TInput(TMember member):member(member){}
	// some functions which use member
private:
	TMember 	member;
};

int sc_main(int argc, char** argv){
	sc_signal<sc_uint<12> >    signal1("signal1");
	TInput<sc_uint<12> >       input(signal1);       // here is the problem, because &signal1 does not return 
	return 0;                                        // its own reference but a const reference to its member
                                                         // so the compiler is telling me, that i want to call a function which does not exist
}

here is a link to sc_signal class of systemc lysium documentation http://www.iro.umontreal.ca/~lablasso/docs/SystemC2.0.1/html/classsc__signal.html

especially this function            operator const T & () const

 

its implementation (of sc_logic) can be found under following link: http://www.lysium.de/docs/systemc-2.2/docs/html/sc__signal_8h-source.html

00132     operator const T& () const
00133     { return read(); } 
00113     // read the current value
00114     virtual const T& read() const
00115     { return m_cur_val; }
00648     sc_dt::sc_logic   m_cur_val;         // current value of object.

I hope there is any solution to my problem and thanks in advance.

Share this post


Link to post
Share on other sites

Dave,

 

I think you misinterpret the method operator const T& () const

This is a cast operator that would allow to cast your signal to its underlying type. This can be called implictly, as in :

sc_signal<int> sig;
sig.write(2);

int val = sig; # val gets the value 2

But this is not your case : your method's parameter's type is "sc_signal<T> &", so no conversion should occur here.

Share this post


Link to post
Share on other sites

Fabien

 

Yes, you are right. I have found that this was not the source which caused my problem. It was rather a problem in which 2 variables (one of type T and one of type sc_signal<T>) had the same name but the wrong one was given to the function call. This happened in a Constructor, so a simple this-> before the name of the variable solved that problem. 

Anyway thank you for the reply.

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

×