Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Identifier is undefined using structs

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!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading