I recently discovered something odd and I'm trying to find some documentation in the C specs or anywhere else for that matter that explains this.
Assume the following is running on a 32bit machine:
VOID myFunction(PVOID pMyPointer);
{
// assume that in this case pMyPointer = 0x87654321 when
// passed into this function.
ULONG64 pMyBigPointer = (ULONG64)pMyPointer;
.......
}
While debugging a problem I learned that in this case the value of pMyBigPointer was not simply 0x87654321 but instead was 0xffffffff87654321. During the cast the PVOID was treated as a signed number and it carried the sign bit out in the 64bit cast.
This seems odd that ANY pointer would be treated as a signed number. I guess for pointer math you could use negative pointers but this seems pretty hairy. I know how to fix this issue but I'm looking for the explaination as to why PVOID is treated differently than other pointers in this case. Some links backing this up would be nice too.
Thanks in advance.
Assume the following is running on a 32bit machine:
VOID myFunction(PVOID pMyPointer);
{
// assume that in this case pMyPointer = 0x87654321 when
// passed into this function.
ULONG64 pMyBigPointer = (ULONG64)pMyPointer;
.......
}
While debugging a problem I learned that in this case the value of pMyBigPointer was not simply 0x87654321 but instead was 0xffffffff87654321. During the cast the PVOID was treated as a signed number and it carried the sign bit out in the 64bit cast.
This seems odd that ANY pointer would be treated as a signed number. I guess for pointer math you could use negative pointers but this seems pretty hairy. I know how to fix this issue but I'm looking for the explaination as to why PVOID is treated differently than other pointers in this case. Some links backing this up would be nice too.
Thanks in advance.