简体   繁体   中英

Declare vector of SystemC type sc_fix

I am trying to make a std::vector of type sc_fix . I know that I can make std::vector<sc_fixed<WL,IWL, ...>> name; . However I would like to use the non-template version sc_fixed . However I am not sure how to instantiate this vector and set the word and integer bit lengths as I can not declare it the same was as the templated version.

I have tried making an array to fill in a memory space of the same type, but this gives me an error as well.

sc_fix* img_num (32, 15, SC_RND_ZERO, SC_SAT_ZERO);
img_num[0] = 12.12;
img_num[1] = 12.12;
img_num[2] = 12.12;
img_num[3] = 12.12;
std::vector<sc_fix> img (img_num, img_num+sizeof(img_num) / sizeof(img_num[0]));

This gives me the error

Main_Test.cpp: In function ‘int sc_main(int, char**)’:
Main_Test.cpp:24: error: initializer expression list treated as compound expression
Main_Test.cpp:24: error: cannot convert ‘sc_dt::sc_o_mode’ to ‘sc_dt::sc_fix*’ in initialization
make: *** [Main_Test] Error 1

What is causing this error and how can I fix it?

You have to remove the * after sc_fix do declare a variable of type sc_fix , not pointer-to sc_fix* , and call it's constructor:

sc_fix img_num (32, 15, SC_RND_ZERO, SC_SAT_ZERO);

The compiler tried to initialize a pointer and complained about the too many initializes provided.

But I think what you want to do is allocate vector with 4 numbers:

std::vector<sc_fix> img_num (4, sc_fix(32, 15, SC_RND_ZERO, SC_SAT_ZERO));
img_num[0] = 12.12;
img_num[1] = 12.12;
img_num[2] = 12.12;
img_num[3] = 12.12;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM