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