做64bit的编程有什么要注意的么?

roman_v 2009-11-13 04:51:48
如题。要把程序转成64bit的,编译通过,警告都很少,但是一运行就出错,各位有没有做过的,给点建议。。

我现在知道的有:
64bit long长度是64bit 指针长度也是64bit
编译器要用64bit的
预定义_WIN64
SetWindowLong要替换成SetWindowLongPtr

MoveWindow(HWND,int,int,int,int,BOOL)这就执行不下去了,是不是因为我传了4个LONG 进去? 强制转换成int也不行。
...全文
547 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
roman_v 2009-11-15
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 squiffy 的回复:]
lz:实在抱歉,是我错了。问了一个同事,应该是这样的:

64位平台上的编译器对int尺寸有3种处理方式

1. ILP : int, long, 和 pointer 都是 64bit。

2. LP : int 是 32bit,long 和 pointer都是 64bit。

3. LLP: int 和 long 都是 32bit,pointer 和 long long 是 64bit。

VC 遵循 LLP 模式。大部分平台上的GCC都使用 LP 模式,

但是Windows平台上的GCC(MinGW)遵循 VC,使用LLP。

LZ你是对的,实在抱歉,误导你了。。。

感谢让我弄清楚了这个问题。

[/Quote]


原来是这样子啊,学习了,是你让我弄清楚了这个问题才对。。
ahao 2009-11-14
  • 打赏
  • 举报
回复
windows下,只有指针变64位
roman_v 2009-11-14
  • 打赏
  • 举报
回复
C标准没有定义int长度吧,这个是由编译器决定的。
roman_v 2009-11-14
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 squiffy 的回复:]
引用 9 楼 roman_v 的回复:
Common Visual C++ 64-bit Migration Issues

When you use Visual C++ to create applications to run on a 64-bit Windows operating system, you should be aware of the following issues:

    *

      An int and a long are 32-bit values on 64-bit Windows operating systems. For programs that you plan to compile for 64-bit platforms, you should be careful not to assign pointers to 32-bit variables. Pointers are 64-bit on 64-bit platforms, and you will truncate the pointer value if you assign it to a 32-bit variable.
    *

      size_t, time_t, and ptrdiff_t are 64-bit values on 64-bit Windows operating systems.



这个说的很清楚了:
1、指针不要赋值给32位的变量。
2、size_t,time_t and ptrdiff_t是64bits。

可能你会问,为什么不说int?因为int类型是C语言内置关键字,C语言标准定义int类型和CPU的数据总线长度一致。---这个是C的标准,在任何编译器下都得执行。
因此,很多编程规范里面曾经提过,不能滥用int类型,我以前在嵌入式平台写代码的时候,都不允许用int定义变量。
[/Quote]


An int and a long are 32-bit values on 64-bit Windows operating systems.

那这句话怎么理解。。
Practise_Think 2009-11-14
  • 打赏
  • 举报
回复
我最近编译x64时,有一大堆警告,主要是 size_t 的赋值
码侬 2009-11-14
  • 打赏
  • 举报
回复
mark
squiffy 2009-11-14
  • 打赏
  • 举报
回复
lz:实在抱歉,是我错了。问了一个同事,应该是这样的:

64位平台上的编译器对int尺寸有3种处理方式

1. ILP : int, long, 和 pointer 都是 64bit。

2. LP : int 是 32bit,long 和 pointer都是 64bit。

3. LLP: int 和 long 都是 32bit,pointer 和 long long 是 64bit。

VC 遵循 LLP 模式。大部分平台上的GCC都使用 LP 模式,

但是Windows平台上的GCC(MinGW)遵循 VC,使用LLP。

LZ你是对的,实在抱歉,误导你了。。。

感谢让我弄清楚了这个问题。
squiffy 2009-11-13
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 roman_v 的回复:]
Common Visual C++ 64-bit Migration Issues

When you use Visual C++ to create applications to run on a 64-bit Windows operating system, you should be aware of the following issues:

    *

      An int and a long are 32-bit values on 64-bit Windows operating systems. For programs that you plan to compile for 64-bit platforms, you should be careful not to assign pointers to 32-bit variables. Pointers are 64-bit on 64-bit platforms, and you will truncate the pointer value if you assign it to a 32-bit variable.
    *

      size_t, time_t, and ptrdiff_t are 64-bit values on 64-bit Windows operating systems.

[/Quote]

这个说的很清楚了:
1、指针不要赋值给32位的变量。
2、size_t,time_t and ptrdiff_t是64bits。

可能你会问,为什么不说int?因为int类型是C语言内置关键字,C语言标准定义int类型和CPU的数据总线长度一致。---这个是C的标准,在任何编译器下都得执行。
因此,很多编程规范里面曾经提过,不能滥用int类型,我以前在嵌入式平台写代码的时候,都不允许用int定义变量。
roman_v 2009-11-13
  • 打赏
  • 举报
回复
Common Visual C++ 64-bit Migration Issues

When you use Visual C++ to create applications to run on a 64-bit Windows operating system, you should be aware of the following issues:

*

An int and a long are 32-bit values on 64-bit Windows operating systems. For programs that you plan to compile for 64-bit platforms, you should be careful not to assign pointers to 32-bit variables. Pointers are 64-bit on 64-bit platforms, and you will truncate the pointer value if you assign it to a 32-bit variable.
*

size_t, time_t, and ptrdiff_t are 64-bit values on 64-bit Windows operating systems.
roman_v 2009-11-13
  • 打赏
  • 举报
回复
你看好标题撒。。这个是在64-Bit Programming with Visual C++ \ x64 Software Conventions 下面的,那必须是讲64位的
squiffy 2009-11-13
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 roman_v 的回复:]
貌似我们两都错了,msdn上说int和long都是32bit的。。
http://msdn.microsoft.com/en-gb/library/94z15h2c%28VS.80%29.aspx
[/Quote]
INT32
int, long
4
Doubleword

这个表的意思是:对IN32等VC内部数据变量的解释,意思在C语言下对应int、long。并没有说在64位下,int、long也是32bit的。

为了支持更好的移植性,在VC下编程使用INT32、INT64这样的定义是很好的一个习惯。这样的程序在32到64位平台移植不会有问题的。说穿了内部就是类似这样实现的:

#if _WIN64
#define INT32 long
#else
#define INT32 int
#endif

这样可以保证无论你在32位平台,64位平台,定义的数据类型都是你期望的位数,明显这样的实现对:申请内存的大小、字节对齐、位操作等来说是至关重要的。

int绝对是64bit的。你说long在64位下是64位,我也有点疑惑,我印象long定义就是32bit的,这个是C标准。
roman_v 2009-11-13
  • 打赏
  • 举报
回复
貌似我们两都错了,msdn上说int和long都是32bit的。。
http://msdn.microsoft.com/en-gb/library/94z15h2c%28VS.80%29.aspx
tcbhj 2009-11-13
  • 打赏
  • 举报
回复
32位64位编程没区别
squiffy 2009-11-13
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 roman_v 的回复:]
那你和我看的不一样嘛,我看的是C++的内置类型,int不变,long变64位。。不过windows有int64这种东西的。。
[/Quote]
int不变是一定错的,这个我是能肯定的。

int的含义就是等于CPU的数据总线的长度

指针的含义就是等于CPU的地址总线的长度

因此,不同位的操作系统对上面这两个影响最大。
roman_v 2009-11-13
  • 打赏
  • 举报
回复
那你和我看的不一样嘛,我看的是C++的内置类型,int不变,long变64位。。不过windows有int64这种东西的。。
squiffy 2009-11-13
  • 打赏
  • 举报
回复
我知道的:

最重要的是:指针长度64Bit,int型的是64Bit的。

好像long的,在64位操作系统下还是32bit的。
roman_v 2009-11-13
  • 打赏
  • 举报
回复
没有吸引力那再加点。。

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧