注册 登录
编程论坛 C++教室

How to compile to 64-bit program?

HJin 发布于 2007-07-20 15:53, 1230 次点击

Hi guys, I want to ask

Is it possible to compile the following source code to a 64-bit program on a 32-bit system?

I have MS VS2005 + Dev-C++ 4.9.9.2 installed on my 32-bit windows xp professional.


#include <iostream>
using namespace std;


int main()
{
    long long i=1000000000000; // this number overflows 32-bit integer
    cout<<i<<endl;
    return 0;
}


8 回复
#2
stupid_boy2007-07-20 16:05

你试一试不就知道了?

#3
一番宝瓶2007-07-20 20:13

Maybe we express it in 32-bit OS by using array to deal with big integer.
I got a question like this before as well.

" what's the result(c) in a 32-bit OS? "



#include<iostream>
using namespace std;


int main()
{
long x = 987654321, c = 0, d = 1, e = 6;
while(x--){
  c += d,
  d += e,
  e += 6;
}

cout<<c<<endl;  //in an 128-bit OS,the code could be run

return 0;
}

#4
野比2007-07-21 00:27

你用VS2005(安装64位支持),然后在编译时使用64位方式。

我没试过,have a go

#5
leeco2007-07-21 01:20

用G++编译器,可以使用long long 类型和cout<<i<<endl;进行输出,用printf("%lld\n",i);可以通过编译但输出结果不正确。
在VC++6.0上,我不能使用long long进行声明,可以使用__int64但不能使用cout<<i<<endl;编译错(提示<<运算有不明确,估计没有对__int类型重载过<<运算)非常奇怪。同样,用printf("%lld\n",i);可以通过编译但输出结果不正确。

我是32位机 OS:WINXP SP2

#6
野比2007-07-21 09:06

用long long有用么?
64位是系统的地址总线宽度..哪是这么来的啊..
要这样能行, 我原来学虚拟机的时候用的基础变量位宽都是128bits, 导师还说"为128位计算机做好准备"...
(^^!)

请指教..

#7
leeco2007-07-21 22:31
回复:(野比)用long long有用么?64位是系统的地址总...
子不闻实践是检验真理的唯一标准乎?你可以在32位机上试试就知道了
#8
leeco2007-07-29 17:17

我发觉在G++和VC++6.0上都可以使用printf("%I64d\n",i);对64位整型进行输出

#include <iostream>

using namespace std;

int main()
{
long long i=1234567890123ll;//初始化的时候G++对于超过long表示范围的数需要加后缀ll,而VC++6.0上不需要,确切の说是不能加
printf("%I64d\n",i);
}

#9
野比2007-07-29 23:07

确实没试过..原来VM都是拿汇编学的..
有时间试试..

1