-2

I know this question is asked tons of times, but I cannot seem to link it to my problem.

My problem is something to do with filling out a web of structs

Here is my buggy code

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


This is the buggy code in a function

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

Here is how the struct web looks like

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

instruction

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

};

Tell me what I am doing wrong thank you

Just so you know they are all wrong in that starting function

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;
       ^
SSpoke
  • 5,239
  • 8
  • 66
  • 112

2 Answers2

2

Your definition of struct emu_cpu is not visible at the point of definition of function fpuInit. For this reason all references to struct emu_cpu in fpuInit definition are seen as forward declarations of a new, incomplete type.

If your struct emu_cpu is defined in a header file, make sure it is included into the file that defines fpuInit.

AnT
  • 291,388
  • 39
  • 487
  • 734
0

Anonymous unions are only allowed at the end of a structure tree:

In

a->b.c.d =

d can be an anonymous ( without name ) struct or union,

b and c can't, and need to have names.

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

Community
  • 1
  • 1
Arif Burhan
  • 477
  • 3
  • 12
  • I suspect that you misunderstand the meaning of the term "anonymous struct". There isn't a single anonymous struct in OP's code. I see a couple of anonymous unions, but no anonymous structs. – AnT Mar 25 '16 at 01:00