Jump to content
Ganesan R

Does system C support matrix of unknown size

Recommended Posts

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_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];


    int m,n;

Does system C does not support variable size matrix?



Share this post

Link to post
Share on other sites

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.


Ameya Vikram Singh


Share this post

Link to post
Share on other sites

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


int** matrix;

I suggest you read at least one of the following:

For simplicity, I like the following tool:


Share this post

Link to post
Share on other sites

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.


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now