C错误:取消引用指向不完整类型的结构,struct

时间:2016-03-25 00:13:51

标签: 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 struct

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;
       ^

2 个答案:

答案 0 :(得分:1)

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

如果您在头文件中定义了struct emu_cpu,请确保它已包含在定义fpuInit的文件中。

答案 1 :(得分:0)

只允许在结构树的 end 中使用匿名联合:

a->b.c.d =

d可以是匿名(没有名称)结构或联合,

b和c不能,并且需要有名字。

参考:** Are "anonymous structs" standard? And, really, what *are* they? **