Ganesan R Posted February 22, 2018 Report Share Posted February 22, 2018 Dear Sir, I am getting the following errors in running this program: error C2466: cannot allocate an array of constant size 0 error C2133: 'matrix' : unknown size Assume I am getting m and n through functions already written and declared in constructor. SC_MODULE(sc_fifo_array) { public: SC_HAS_PROCESS(sc_fifo_array); sc_fifo_array(sc_module_name name_):sc_module(name_) { int m,n; int *matrix[m]; for (int i=0; i<m; i++) matrix=new int[n]; matrix[0][0]=20; cout<<"\nmatrix="<<matrix[0][0]<<"\n"; } public: int m,n; }; Does system C does not support variable size matrix? Quote Link to comment Share on other sites More sharing options...
AmeyaVS Posted February 22, 2018 Report Share Posted February 22, 2018 Hello @Ganesan R, What are the possible values of m and n?(It seems to take default value of 0) For array of SystemC objects there is a construct available for such purposes: sc_vector. Try search here in the forums to find the necessary discussions. e.g.: http://forums.accellera.org/topic/5775-vector-of-modules-errors/?tab=comments#comment-14006 Hope it helps. Regards, Ameya Vikram Singh Quote Link to comment Share on other sites More sharing options...
David Black Posted February 22, 2018 Report Share Posted February 22, 2018 This has nothing to do with SystemC, but more to do with your declaration. You are declaring an array of pointers to integers on the stack. Stack in SystemC is 64k by default, which means you are limited to 64k/sizeof(int*). I suspect you intended to declare a pointer to an array of ints: int (*matrix)[]; // Pointer to array of int or int** matrix; I suggest you read at least one of the following: https://www.codeproject.com/Articles/7042/How-to-interpret-complex-C-C-declarations https://www.geeksforgeeks.org/complicated-declarations-in-c/ https://medium.com/@bartobri/untangling-complex-c-declarations-9b6a0cf88c96 For simplicity, I like the following tool: https://cdecl.org swami060 1 Quote Link to comment Share on other sites More sharing options...
maehne Posted February 22, 2018 Report Share Posted February 22, 2018 David is right about the wrong declaration of your matrix. However, your code has several issues related purely to C++ and not SystemC: Your local variables m, n in constructor sc_fifo_array shadow the member variables m, n. Decide at which scope you need your matrix and drop the other pair. I would recommend to declare m and n as constants and assign their values upon declaration or in the constructor's member variables initialization list. I would recommend to not use raw memory allocation for your matrix. It will be a hassle to ensure that it gets correctly deallocated. Instead consider to use an appropriate container providing you the functionality of a matrix. You may consider, e.g., the Eigen library. Advantage is that these containers usually implement efficiently additional convenient operations, which you otherwise have to implement and test yourself. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.