Jump to content
Aaron Yang

How to connect array of ports?

Recommended Posts

Hey I am kinda new to system C, I met this error when connecting ports declared as array: 

sc_main.cpp: In function 'int sc_main(int, char**)':
sc_main.cpp:16:21: error: expression cannot be used as a function

This is sc_main.cpp

#include <systemc.h>
#include "fir.h"
#include "tb.h"

int sc_main (int, char *[]){
    sc_clock clock("clock", 10, SC_NS);
    sc_signal<bool> reset;
    sc_signal<sc_fixed<16,2>> sample_in[2];
    sc_signal<sc_fixed<16,2>> sample_out[4];
    tb tb0("tb0_name");
    fir1("fir1_name", true);

This is the tb.h file

#include <systemc.h>
    sc_in<bool>         clk;
    sc_out<bool>        rstn;
    sc_out<sc_fixed<16,2>>  in[2];
    sc_in<sc_fixed<16,2>>   out[4];

This is the fir.h

#include <systemc.h>

SC_MODULE(fir) {
    sc_in<bool>                             rst_n;
    sc_in<bool>                             clk;
    sc_in<sc_fixed<16,2>>      				din[2];
    sc_out<sc_fixed<16,2>>   				dout[4];

What should I do in this case?

Share this post

Link to post
Share on other sites
19 minutes ago, Aaron Yang said:

What should I do in this case?

Usually you should use sc_vector instead of array. The problem with array is that names of signals and ports in array will be initialized to meaningless values (port_0 ... port_1 ).

If you still want to use arrays, then bind with a loop.

Here is example, both for array and sc_vector.


#include <systemc.h>

static const int N_PORTS = 4;

struct dut : sc_module {

    sc_in<int>             in_array[N_PORTS];
    sc_vector<sc_in<int>>  in_vector{"in_vector", N_PORTS};

    SC_CTOR(dut) {}


struct test : sc_module {

    dut d0{"d0"};
    sc_signal<int>             sig_array[N_PORTS];
    sc_vector<sc_signal<int>>  sig_vector{"sig_vector", N_PORTS};

    SC_CTOR(test) {

        for (size_t i = 0; i < N_PORTS; ++i) {




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