什么是长的位大小在64位的Windows? [英] What is the bit size of long on 64-bit Windows?

查看:126
本文介绍了什么是长的位大小在64位的Windows?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不是很久以前,有人告诉我,不是64位在64位机器,我应该总是用 INT 。这没有道理给我。我所看到的文档(如一个在苹果的官方网站)说,确实是64位编译支持64位CPU的时候。我抬头一看它是在64位Windows,发现

Not to long ago, someone told me that long are not 64 bits on 64 bit machines and I should always use int. This did not make sense to me. I have seen docs (such as the one on Apple's official site) say that long are indeed 64 bits when compiling for a 64-bit CPU. I looked up what it was on 64-bit Windows and found

      
  • 的Windows: INT 留在长度为32位,而特殊的新的数据类型   被定义为64位整数。
  •   
  • Windows: long and int remain 32-bit in length, and special new data types are defined for 64-bit integers.

(从<一个href="http://www.intel.com/cd/ids/developer/asmo-na/eng/197664.htm?page=2">http://www.intel.com/cd/ids/developer/asmo-na/eng/197664.htm?page=2)

我应该怎么使用?我应该定义类似 UW 软件((UN)签署宽度)为如果无法在Windows,否则做目标CPU bitsize支票?

What should I use? Should I define something like uw, sw ((un)signed width) as a long if not on Windows, and otherwise do a check on the target CPU bitsize?

推荐答案

在Unix世界中,有整数和指针的64位平台的大小几个可能的安排。这两个使用最广泛的是ILP64(实际上,只有极少数这样的例子,克雷是这样)和LP64(几乎一切)。该acronynms来自'的int,long,指针是64位的'和'长,指针是64位。

In the Unix world, there were a few possible arrangements for the sizes of integers and pointers for 64-bit platforms. The two mostly widely used were ILP64 (actually, only a very few examples of this; Cray was one such) and LP64 (for almost everything else). The acronynms come from 'int, long, pointers are 64-bit' and 'long, pointers are 64-bit'.

Type           ILP64   LP64   LLP64
char              8      8       8
short            16     16      16
int              64     32      32
long             64     64      32
long long        64     64      64
pointer          64     64      64

在ILP64系统摒弃,取而代之的 LP64 (也就是,几乎所有的后来者用过LP64的基础上,阿斯小组的建议,只与64位操作系统使用不同的方案)长的遗产系统。所有现代的64位Unix系统使用LP64。的MacOS X和Linux都是现代的64位系统。

The ILP64 system was abandoned in favour of LP64 (that is, almost all later entrants used LP64, based on the recommendations of the Aspen group; only systems with a long heritage of 64-bit operation use a different scheme). All modern 64-bit Unix systems use LP64. MacOS X and Linux are both modern 64-bit systems.

微软采用了不同的方式来过渡到64位:LLP64('很久很久,指针是64位)。这具有意义的优点是32位软件可以在不改变重新编译。它有被来自其他人一样不同的缺点,而且还需要code加以修订,以充分利用64位的能力。总是有必要的修订;这只是一组不同的,从需要在Unix平台上的那些版本。

Microsoft uses a different scheme for transitioning to 64-bit: LLP64 ('long long, pointers are 64-bit'). This has the merit of meaning that 32-bit software can be recompiled without change. It has the demerit of being different from what everyone else does, and also requires code to be revised to exploit 64-bit capacities. There always was revision necessary; it was just a different set of revisions from the ones needed on Unix platforms.

如果您规避设计与平台无关的整数类型的名称你的软件,可能使用C99 &LT; inttypes.h&GT; 头,其中,当类型可在平台,提供了,在签署(上市)和无符号(未上市; preFIX与'U')

If you design your software around platform-neutral integer type names, probably using the C99 <inttypes.h> header, which, when the types are available on the platform, provides, in signed (listed) and unsigned (not listed; prefix with 'u'):

  • 中int8_t - 8位整数
  • int16_t - 16位整数
  • int32_t - 32位整数
  • 的int64_t - 64位整数
  • uintptr_t形式 - 无符号整数大到足以容纳指针
  • 还会将intmax_t - 整数平台上的最大尺寸(可能大于的int64_t
  • int8_t - 8-bit integers
  • int16_t - 16-bit integers
  • int32_t - 32-bit integers
  • int64_t - 64-bit integers
  • uintptr_t - unsigned integers big enough to hold pointers
  • intmax_t - biggest size of integer on the platform (might be larger than int64_t)

您可以再code。使用这些类型的地方事务,并且非常小心与系统类型(这可能是不同的),您的应用程序。有一个使用intptr_t 键入 - 持有三分球有符号整数类型;你应该计划在不使用它,或者只是用它作为两个 uintptr_t形式值(减法的结果 ptrdiff_t型 )。

You can then code your application using these types where it matters, and being very careful with system types (which might be different). There is an intptr_t type - a signed integer type for holding pointers; you should plan on not using it, or only using it as the result of a subtraction of two uintptr_t values (ptrdiff_t).

不过,因为这个问题指出,(难以置信),也有不同的系统为整数数据类型在64位机器的尺寸。习惯它;世界是不会改变的。

But, as the question points out (in disbelief), there are different systems for the sizes of the integer data types on 64-bit machines. Get used to it; the world isn't going to change.

这篇关于什么是长的位大小在64位的Windows?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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