Jump to content

sc_signal & Operator


HSDave

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.

Link to comment
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.

Link to comment
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.

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...