Jump to content

Does system C support matrix of unknown size

Ganesan R

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?



Link to comment
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


Link to comment
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:


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


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.

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