Let's look at the following code:
#include <stdio.h>#include<windows.h>#include<memory>classtest{ Public: Test (inti): A (i) {}~Test () {} Public: voidPrint () {printf ("a=%d\n", a); }Private: intA;};intMain () {std::shared_ptr<Test> AA (NewTest (6)); AA-Print (); wprintf (L"test* Size:%d\n",sizeof(test*)); wprintf (L"ULONG Size:%d\n",sizeof(ULONG)); ULONG Data= (ulonglong) AA.Get(); (Test*) data)Print ();}
x86 environment, the operation is normal (the output is as follows):
A=6
test* Size:4
ULONG Size:4
A=6
But if you compile the x64 program and run it, there's a problem here:
A=6
test* Size:8
ULONG Size:4
----------------------------> Crash.
In fact, from the printed size, it is obvious that these two size inconsistencies resulted in the pointer being 8 bytes in the x64 bit environment and only 4 bytes in the x86 environment (usually).
So if the program wants to run in both x86 and x64 environments, you need to consider this.
x86 program on Windows is OK but x64 program crashes