C ++-可笑的长距离 [英] C++ - ridiculous long long range

查看:62
本文介绍了C ++-可笑的长距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我和我的朋友刚刚遇到了一个很长距离的怪异问题. 因此,基本上,我的计算机上装有64位处理器,但装有32位系统.他同时拥有32位操作系统和CPU.

Me and my friend have just encountered a very weird issue with long long range. So basically, my computer has a 64bit processor but a 32 bit system on it. He has both 32 bit OS and CPU.

首先,我们打印sizeof(long long).对于我们俩来说都是8.

First, we printfed sizeof(long long). For both of us that was 8.

然后我们这样做:

long long blah = 1;

printf ("%lld\n", blah<<40);

对我来说,这将返回1099511627776(这是正确的结果).对他来说是0.

For me this returns 1099511627776 (which is the correct result). For him it is 0.

那怎么可能?我们都有相同的sizeofs.

How is that possible? We both have the same sizeofs.

谢谢.

我在Win7下使用代码块12.11进行编译和运行.他使用Win XP和相同版本的CB.

I compiled and ran it under Win7 with Code Blocks 12.11. He uses Win XP and the same version of CB.

请求的源代码:

#include <cstdio>

int main()
{
    long long blah = 1;

    printf ("%lld\n", blah<<40);

    return 0;
}

#include <cstdio>

int main()
{
    printf ("%d", sizeof(long long));

    return 0;
}

推荐答案

我想您和您的朋友正在链接到臭名昭著的MSVCRT.DLL的不同版本或其他库.

I would guess that you and your friends are linking to different versions of the infamous MSVCRT.DLL or possibly some other library.

从代码::块常见问题解答:

From the Code::Blocks FAQ:

问:什么代码::: Blocks不是?

Q: What Code::Blocks is not?

A:Code :: Blocks既不是编译器,也不是链接器.如果目标平台尚未提供,则Code :: Blocks发行包可能包含编译器套件(MinGW/GCC).但是,它是按原样"提供的,而不是由Code :: Blocks开发团队开发/维护的.

A: Code::Blocks is not a compiler, nor a linker. Release packages of Code::Blocks may include a compiler suite (MinGW/GCC), if not provided by the target platform already. However, this is provided "as-is" and not developed/maintained by the Code::Blocks development team.

因此,语句我在带有代码块12.11的Win7下编译并运行了它"并不是严格意义上的;您不能使用非编译器进行编译.

So the statement "I compiled and ran it under Win7 with Code Blocks 12.11" isn't strictly true; you cannot compile with something that isn't a compiler.

找出你们两个实际使用的编译器(请参见上文:它不是代码块")和库.

Figure out what compiler you two are actually using (see, above: it is not "Code Blocks") and what library.

这篇关于C ++-可笑的长距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆