简体   繁体   English

数组类型具有不完整的元素类型“结构指令”

[英]Array type has incomplete element type 'struct instruction'

How do I make this struct instruction visible to struct cpu state?如何使此 struct 指令对 struct cpu 状态可见? Like If I put cpu state struct first it doesn't work because some other arguments won't be visible to struct instruction but if I put it reverse again I have a problem.就像如果我先把 cpu state struct 放在首位,它就不起作用,因为其他一些参数对 struct 指令是不可见的,但是如果我再次将其颠倒过来,我就会遇到问题。

struct  cpu_state
{
    int nextinstructionlinenumber;
    char filename[200];
    char RLO;

    struct instruction instructionlist[INSTRUCTIONLIST_SIZE];
    int instructionlistnumber;
    struct variable variablelist[INSTRUCTIONLIST_SIZE];
    int variablelistnumber;

};
struct cpu_state CPU; 


struct instruction{
    char name[LINE_CHAR_NUM];
    void(*function)(struct cpu_state* pstate, struct line* pline);
};

You can create incomplete structure declarations provided they are just used for pointers.您可以创建不完整的结构声明,前提是它们仅用于指针。 For example, the following order will work.例如,以下顺序将起作用。 Note that I created a dummy definition for struct variable since it was absent from the post.请注意,我为struct variable创建了一个虚拟定义,因为帖子中没有它。 You can replace it with whatever you like:你可以用你喜欢的任何东西替换它:

struct variable {
    int     dummy_val;
};

struct cpu_state;
struct line;

struct instruction{
    char name[LINE_CHAR_NUM];
    void(*function)(struct cpu_state* pstate, struct line* pline);
};

struct  cpu_state
{
    int nextinstructionlinenumber;
    char filename[200];
    char RLO;

    struct instruction instructionlist[INSTRUCTIONLIST_SIZE];
    int instructionlistnumber;
    struct variable variablelist[INSTRUCTIONLIST_SIZE];
    int variablelistnumber;

};

struct cpu_state CPU;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM