C++ - ridiculous long long range

ⅰ亾dé卋堺 提交于 2019-12-06 11:08:01

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:

Q: What Code::Blocks is not?

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.

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.

Could be one of two problems: either the printing system cannot cope with long long or the shift operator does not work over 32 bits. Try this

#include <cstdio>
int main()
{
   union
   {
      long long one;

      // Intel based systems are back to front
      struct {
         long lo;
         long hi;
      } two;
   } xxx;

   xxx.one = 1LL;
   xxx.one = xxx.one << 40;
   printf ("%016llx %08x %08x\n", xxx.one, xxx.two.hi, xxx.two.lo);
   return 0;
}

If the first number is all zeros but one of the other two isn't, then it is the printf that cannot cope. If all the numbers are zeros, then the shift operator isn't defined for 64 bits.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!