Jump to content

Could I initialize sc_vector when I defining it?


enchanter

Recommended Posts

I try to define a sc_vector like this in SC_MODULE

 

sc_vector<sc_signal<sc_uint<C_WIDTH> > > sDin("sDin", C_SIZE); 

 

Then I got this error:


expected identifier before string constant

   sc_vector<sc_signal<sc_uint<C_WIDTH> > > sDin("sDin", C_SIZE);

                                                                                      ^    

 

 

I am not sure what is missing from there. 


 

Link to post
Share on other sites

 

I try to define a sc_vector like this in SC_MODULE
 
sc_vector<sc_signal<sc_uint<C_WIDTH> > > sDin("sDin", C_SIZE); 
 
Then I got this error:
expected identifier before string constant
   sc_vector<sc_signal<sc_uint<C_WIDTH> > > sDin("sDin", C_SIZE);
                                                                                      ^    
 
 
I am not sure what is missing from there. 

 

Hello Sir,

SystemC vectors are derived from ANSI C++ STL vectors.

The following are how some STL vectors might be declared,

defined and initialized.

std::vector<int> first;                                /* empty vector of intwgwrs */std::vector<int> second (4,100);                       /* four integers with value 100 */std::vector<int> third (second.begin(),second.end());  /* iterating through second */std::vector<int> fourth (third);                       /* a copy of third *//* the iterator constructor can also be used to construct from arrays: */int myints[] = {16,2,77,29};std::vector<int> fifth (myints, myints + sizeof(myints) / sizeof(int) );

Hope this helps.

Link to post
Share on other sites

I try to define a sc_vector like this in SC_MODULE

 

sc_vector<sc_signal<sc_uint<C_WIDTH> > > sDin("sDin", C_SIZE);

 

Your problem is not specific to sc_vector, but to C++ in general: You can't initialize a member of an SC_MODULE (or any other C++ class) in the body of the class itself.  You need to do it in the constructor, using an initializer list:

 

SC_MODULE(mod)
{
  sc_vector<sc_signal<sc_uint<C_WIDTH> > > sDin; 
  SC_CTOR(mod)
    : sDin("sDin", C_SIZE) // C++ initializer list
  {
    // ...
  }
};
Greetings from Oldenburg,

  Philipp

Link to post
Share on other sites

Archived

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

×
×
  • Create New...