Home > Back-end >  Identifier is undefined using structs
Identifier is undefined using structs

Time:04-21

Just a (hopefully) quick and simple question that I can't seem to figure out. I'm working on a project and this code was given to us by the instructor and I can't for the life of me figure out why the compiler thinks PartitionTableEntry is undefined when it exists right above it in the code.

struct PartitionTableEntry
{
    unsigned char bootFlag;
    unsigned char CHSBegin[3];
    unsigned char typeCode;
    unsigned char CHSEnd[3];
    unsigned int LBABegin;
    unsigned int LBAEnd;
};

struct MBRStruct
{
    unsigned char bootCode[446];
    PartitionTableEntry part1;   // These lines
    PartitionTableEntry part2;   // right here
    PartitionTableEntry part3;   // is where the
    PartitionTableEntry part4;   // issue is
    unsigned short flag;
} MBR;

I'm not too savvy with C so there's probably something simple I'm missing so that's why I am turning to SO. I was told I could just drop this into my code from the instructor and it would work. Hopefully someone can figure this out. Thanks!

CodePudding user response:

You're coding in C, not C . You've defined a type struct PartitionTableEntry; you've not defined a type PartitionTableEntry, so the compiler complains.

The story would be different in C , but you aren't coding in C .

To fix this, you could add typedef struct PartitionTableEntry PartitionTableEntry; before you start defining struct MBRStruct, or you can use struct PartitionTableEntry inside struct MBRStruct.

  • Related