数组类型的元素类型不完整 'struct instruction'

Array type has incomplete element type 'struct instruction'

如何让这个结构指令对结构 cpu 状态可见?就像如果我把 cpu 状态结构放在第一位,它就不起作用,因为一些其他参数对结构指令不可见,但如果我再次把它倒过来,我就有问题了。

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);
};

您可以创建不完整的结构声明,前提是它们仅用于指针。例如,以下命令将起作用。请注意,我为 struct variable 创建了一个虚拟定义,因为它在 post 中不存在。您可以将其替换为任何您喜欢的:

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;