Defining interface in header

If you have a simple question and just want an answer.
Briggybros
Newbie
Posts: 1
Joined: Mon Nov 21, 2016 7:03 pm

Defining interface in header

Post by Briggybros »

Hello, I'm trying to refactor my project so that it is more modular, instead of being one monolithic main.xc. I have an interface, and am trying to split the clients and server of this interface into two separate modules. The problem comes when referencing this interface anywhere. Currently, I have a header with just the interface, which I am including in the headers and body of the server and client modules. However, when building, the function where I define an array of these interfaces errors; "error: array type has incomplete element type", on the line which looks like:

Code: Select all

interface i interf[workerCount];
workerCount is defined;

Code: Select all

#define workerCount = 7
the imported interface header is as follows:

Code: Select all

interface wsi {
    int getLine();
    void ret(int y, int x, char c);
    void lineDone();
};

typedef interface wsi i;
Is there a way to define an interface in such a way which actually compiles?
Gothmag
XCore Addict
Posts: 129
Joined: Wed May 11, 2016 3:50 pm

Post by Gothmag »

To create an array of interfaces you just have typename varname[count]. You don't need to add the interface keyword since you already typedef'd it. In your interface declaration I would just do:

Code: Select all

typedef interface wsi {
    int getLine();
    void ret(int y, int x, char c);
    void lineDone();
} wsi;
It looks a little cleaner, at least to me. Then you just create the array like this.

Code: Select all

wsi wsi_ifs[workerCount];