C错误: dereferencing pointer to incomplete type,结构

标签 c pointers struct dereference incomplete-type

我知道这个问题被问了很多次,但我似乎无法将其与我的问题联系起来。

我的问题与填写结构网络有关

这是我的错误代码

src\fpu.c:17:7: error: dereferencing pointer to incomplete type
    cpu->instr.fpu.control = 0x37F;
       ^


这是函数中的错误代码

void fpuInit(struct emu_cpu *cpu) {
   cpu->instr.fpu.control = 0x37F;
   cpu->instr.fpu.status = 0;
   cpu->instr.fpu.tag = 0xFFFF;
   cpu->instr.fpu.lastDataPointer = 0;
   cpu->instr.fpu.lastDataSeg = 0;
   cpu->instr.fpu.lastIP = 0;
   cpu->instr.fpu.lastIPseg = 0;
   cpu->instr.fpu.opcode = 0;
}

这是 struct web 的样子

CPU

struct emu_cpu
{
    struct emu *emu;
    struct emu_memory *mem;

    uint32_t debugflags;

    uint32_t eip;
    uint32_t eflags;
    uint32_t reg[8];
    uint16_t *reg16[8];
    uint8_t *reg8[8];

    struct emu_instruction          instr;
    struct emu_cpu_instruction_info     *cpu_instr_info;

    uint32_t last_fpu_instr[2];

    char *instr_string;

    bool repeat_current_instr;

    struct emu_track_and_source *tracking;
};

说明

struct emu_instruction
{
    uint16_t prefixes;
    uint8_t opcode;
    uint8_t is_fpu : 1;

    union
    {
        struct emu_cpu_instruction cpu;
        struct emu_fpu_instruction fpu;
    };

    struct 
    {
        struct emu_tracking_info init;
        struct emu_tracking_info need;      
    } track;

    struct 
    {
        uint8_t has_cond_pos : 1;
        uint32_t norm_pos;
        uint32_t cond_pos;
    } source;
};

fpu结构

union FpuMmxRegister {
   long double fp;
   unsigned char  b[10];   //only use 8 of these for mmx
   unsigned short s[4];
   unsigned int   i[2];
   unsigned long long ll;
};

struct emu_fpu_instruction
{
    uint16_t prefixes;

    uint8_t fpu_opcode;
    //uint8_t fpu_modrm;

    struct /* mod r/m data */
    {
        union
        {
            uint8_t mod : 2;
            uint8_t x : 2;
        };

        union
        {
            uint8_t reg1 : 3;
            uint8_t opcode : 3;
            uint8_t sreg3 : 3;
            uint8_t y : 3;
        };

        union
        {
            uint8_t reg : 3;
            uint8_t reg2 : 3;
            uint8_t rm : 3;
            uint8_t z : 3;
        };

        struct
        {
            uint8_t scale : 2;
            uint8_t index : 3;
            uint8_t base : 3;
        } sib;

        union
        {
            uint8_t s8;
            uint16_t s16;
            uint32_t s32;
        } disp;

        uint32_t ea;
    } fpu_modrm;

    //uint32_t ea;

    uint16_t control;
    uint16_t status;
    uint16_t tag;
    uint32_t lastIP;
    uint32_t lastIPseg;
    uint32_t lastDataPointer;
    uint32_t lastDataSeg;
    uint16_t opcode;

    uint32_t last_instr;

    union FpuMmxRegister r[8];

};

请告诉我我做错了什么,谢谢

只是为了让你知道他们在那个启动函数中都是错误的

src\fpu.c:17:7: error: dereferencing pointer to incomplete type
    cpu->instr.fpu.control = 0x37F;
       ^
src\fpu.c:18:7: error: dereferencing pointer to incomplete type
    cpu->instr.fpu.status = 0;
       ^
src\fpu.c:19:7: error: dereferencing pointer to incomplete type
    cpu->instr.fpu.tag = 0xFFFF;
       ^
src\fpu.c:20:7: error: dereferencing pointer to incomplete type
    cpu->instr.fpu.lastDataPointer = 0;
       ^
src\fpu.c:21:7: error: dereferencing pointer to incomplete type
    cpu->instr.fpu.lastDataSeg = 0;
       ^
src\fpu.c:22:7: error: dereferencing pointer to incomplete type
    cpu->instr.fpu.lastIP = 0;
       ^
src\fpu.c:23:7: error: dereferencing pointer to incomplete type
    cpu->instr.fpu.lastIPseg = 0;
       ^
src\fpu.c:24:7: error: dereferencing pointer to incomplete type
    cpu->instr.fpu.opcode = 0;
       ^

最佳答案

您对 struct emu_cpu 的定义在函数 fpuInit 的定义点不可见。因此,fpuInit 定义中对 struct emu_cpu 的所有引用都被视为新的不完整类型的前向声明。

如果您的 struct emu_cpu 是在头文件中定义的,请确保将其包含在定义 fpuInit 的文件中。

关于C错误: dereferencing pointer to incomplete type,结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36212147/

相关文章:

c - 如何在 C 中更改带有 '?' 登录的 if 语句

c - 使用 memcmp 与。 == in c (embedded) 和意外错误

c - 如果打印此内存位置的内容,为什么会出现段错误

c++ - 通过指针成员传递类

swift - 结构内部的 Swift float 问题

c++ - 具有映射的结构 vector 的结构

c - 如何借助 fscanf 找出矩阵中列的大小?

c - 使用 fputc 通过管道写入

python - python中的指针?

c - 退出函数 C 时全局变量更改值