473,320 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Recasting a Structure Pointer

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
Jul 22 '05 #1
1 2377

"Ben Nguyen" <be*****@hotmail.com> wrote in message
news:e6*************************@posting.google.co m...
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;
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: kamran | last post by:
Hi I was wondering if it is possible to recast a pointer in C ? What I mean in detail is that I have compressed data coming from an instrument. These are mostly sample differences from the...
2
by: prakashgkhaire | last post by:
i have two structure where first structure consists val and structure pointer(linklist), 2nd structure consists, val, a varialbe of first structure, pointer of structure. Now i found to pass the...
2
by: Mike | last post by:
Hi, I am new to C and having problems with the following program. Basically I am trying to read some files, loading data structures into memory for latter searching. I am trying to use structres...
5
by: sharat | last post by:
hi all can any body tell how to declare the structure pointer within a class. i have written the following program but gettin error. #include<iostream> using namespace std;
2
Soujiro
by: Soujiro | last post by:
struct sample { string sampleStr; }; int main() { struct sample* structure = (struct sample*) malloc( sizeof( struct sample ) ); structure->sampleStr="Papa"; //...
1
by: =?utf-8?B?5Lq66KiA6JC95pel5piv5aSp5rav77yM5pyb5p6B | last post by:
first, I'm try the POINTER to convesion the pointer type. but failed. class STUDENT(Structure): _fields_ = buffer = c_byte * 1024 student_p = cast(buffer, POINTER(STUDENT)) The parameter...
4
by: ashusharma82 | last post by:
plz check following code pMe i an structure pointer,in which char *linewisechar is made. pMe->linewisechar=(pMe->newcchar+STRLEN(pMe->newcchar)-1); here i am assigning...
3
by: Nasif | last post by:
Dear All I am using a C++ DLL which has two function , one returns a void pointer, other returns a pointer to structure .But I doing my project on C#. Which data types in C# should I use to...
3
by: vivek nandan | last post by:
The following code, struct devinfo{ int a; int b; }; struct devinfo *devinfo; is perfectly legal in C. How is it that the structure pointer is declared with same name of the structure? Does...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.