Recasting a Structure Pointer

B

Ben Nguyen

Im trying to port a hard drive driver that was originally for a different
compiler than the one Im using now. The line that doesnt compile with the new
compiler is:


ActualPartRecord = *((struct partrecord *)
((struct partsector *) SectorArray) -> psPart);


where partsector is a 512 byte structure that contains a 64 byte field 'psPart'
that is being forced into a 16 byte structure (ActualPartRecord is of type
partrecord)

How can 64 bytes (-> psPart) get squeezed into 16? Is this why the compiler is
complaining?

The actual error message is:
"pointer to structure or union required on left side of '->'"


struct partrecord
{
__uchar8 isActive;
__uchar8 startHead;
__uint16 startCylSect;
__uchar8 partType;
__uchar8 endHead;
__uint16 endCylSect;
__ulong32 startLBA;
__ulong32 size;
};


struct partsector
{
__char8 psPartCode[446];
__uchar8 psPart[64];
__uchar8 psBootSectSig0;
__uchar8 psBootSectSig1;
};


Also
SectorArray is declared as:
__uchar8 tempArray[512];
__uchar8 *SectorBuffer =(__uchar8 *) tempArray;


Any suggestions?
Ben
 
N

Nick Hounsome

Ben Nguyen said:
Im trying to port a hard drive driver that was originally for a different
compiler than the one Im using now. The line that doesnt compile with the new
compiler is:


ActualPartRecord = *((struct partrecord *)
((struct partsector *) SectorArray) -> psPart);


where partsector is a 512 byte structure that contains a 64 byte field 'psPart'
that is being forced into a 16 byte structure (ActualPartRecord is of type
partrecord)

How can 64 bytes (-> psPart) get squeezed into 16? Is this why the compiler is
complaining?

It isn't - it's just that only the first 16 bytes are significant - (this is
usually better done with unions).
No.
The actual error message is:
"pointer to structure or union required on left side of '->'"


struct partrecord
{
__uchar8 isActive;
__uchar8 startHead;
__uint16 startCylSect;
__uchar8 partType;
__uchar8 endHead;
__uint16 endCylSect;
__ulong32 startLBA;
__ulong32 size;
};


struct partsector
{
__char8 psPartCode[446];
__uchar8 psPart[64];
__uchar8 psBootSectSig0;
__uchar8 psBootSectSig1;
};


Also
SectorArray is declared as:
__uchar8 tempArray[512];
__uchar8 *SectorBuffer =(__uchar8 *) tempArray;

That declares SectorBuffer not SectorArray.
Any suggestions?
Ben

Apart from SectorArray it looks OK to me but all these brackets are
confusing.
Whenever I get a problem like this I always break it down into several
statements - that usually allows the compiler to
help me out or even occasionaly work around a compiler bug.
Try:

partsector* ps = reinterpret_cast<partsector*>(SectorArray);
__uchar8 *partp = ps->psPart;
partrecord* pr = reinterpret_cast<partrecord*>(pr);
ActualPartRecord = *pr;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,159
Messages
2,570,879
Members
47,416
Latest member
LionelQ387

Latest Threads

Top