Windows上x86程序正常但x64程序崩溃问题
来源:互联网 发布:80后去哪了 知乎 编辑:程序博客网 时间:2024/06/10 11:26
先看下面代码:
#include <stdio.h>#include <windows.h>#include <memory>class Test{public: Test(int i) :a(i) { } ~Test() { }public: void Print() { printf("a=%d\n", a); }private: int a;};int main(){ std::shared_ptr<Test> aa(new Test(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环境下,运行正常(输出如下):
a=6
Test* size: 4
ULONG size: 4
a=6
但如果编译x64的程序后运行,这里就有问题了:
a=6
Test* size: 8
ULONG size: 4
----------------------------> Crash.
这里其实从打印出的size来看,很明显这两个size不一致导致, 指针在x64位环境下为8字节,而在x86环境下只有4字节(通常)。
因此如果程序要想同时可以在x86及x64环境下运行,需要考虑这一点。
0 0
- Windows上x86程序正常但x64程序崩溃问题
- Windows X64上强制用x86模式运行c#程序
- Windows X64上强制用x86模式运行c#程序
- Windows X64上强制用x86模式运行c#程序
- Windows X64上强制用x86模式运行c#程序
- vc中debug版程序正常但release版崩溃
- vc中debug版程序正常但release版崩溃
- vc中debug版程序正常但release版崩溃
- vc 中debug版程序正常 但release版崩溃
- vc中debug版程序正常但release版崩溃
- vc中debug版程序正常但release版崩溃
- vc中debug版程序正常但release版崩溃
- Debug正常Release下程序崩溃问题
- 程序运行在X86和X64机器上由字节分配不一样引发的问题
- 关于Gson.jar导入正常使用,代码无错,但程序执行解析时崩溃的一些问题
- 编译c++程序x64/x86 运行出现 应用程序无法正常启动0xc000007b_学习笔记
- .net 编译时选择anycpu x86 x64的区别: 在 64 位 Windows 操作系统上: 用 x86 编译的程序集将在 WOW64 下运行的 32 位 CLR 上执行。 用 x64 编译
- vc中debug版程序正常但release版崩溃(carefull)
- C++中调用Python脚本
- springmvc+redis项目搭建
- Visual Studio 2013 编译CEF步骤
- java 实现Excel数据导入数据库
- Microsoft source-code annotation language (SAL) 相关
- Windows上x86程序正常但x64程序崩溃问题
- 【leetcode】 Remove Duplicates from Sorted List
- Jenkins新建项目
- Create a Listlink
- [LeetCode] Two sum
- 线程中sleep和wait的区别
- [LeetCode] Longest Substring Without Repeating Characters
- 【转】更简单的非递归遍历二叉树的方法
- Android Studio插件 - FindViewByMe