C语言 C中的点WORD类型是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16863333/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the point WORD type in C?
提问by Nealon
In going through some source code, I found a method in a C program that takes an arguments of the types WORD, DWORD, and PWORD. I know they translate to unsigned numbers, but why are they called WORD?
在浏览一些源代码时,我在 C 程序中找到了一个方法,它采用 WORD、DWORD 和 PWORD 类型的参数。我知道它们会转换为无符号数,但为什么它们被称为 WORD?
回答by Oscar
Word Size and Data Types
字长和数据类型
A word is the amount of data that a machine can process at one time. This fits into the document analogy that includes characters (usually eight bits) and pages (many words, often 4 or 8KB worth) as other measurements of data. A word is an integer number of bytes for example, one, two, four, or eight. When someone talks about the "n-bits" of a machine, they are generally talking about the machine's word size. For example, when people say the Pentium is a 32-bit chip, they are referring to its word size, which is 32 bits, or four bytes.
一个字是一台机器一次可以处理的数据量。这符合包含字符(通常为 8 位)和页面(许多字,通常为 4 或 8 KB 值)作为其他数据度量的文档类比。一个字是整数个字节,例如,一、二、四或八。当有人谈论机器的“n 位”时,他们通常是在谈论机器的字长。例如,当人们说 Pentium 是 32 位芯片时,他们指的是它的字长,即 32 位或 4 个字节。
The size of a processor's general-purpose registers (GPR's) is equal to its word size. The widths of the components in a given architecture for example, the memory bus are usually at least as wide as the word size. Typically, at least in the architectures that Linux supports, the memory address space is equal to the word size[2]. Consequently, the size of a pointer is equal to the word size. Additionally, the size of the C type long is equal to the word size, whereas the size of the int type is sometimes less than that of the word size. For example, the Alpha has a 64-bit word size. Consequently, registers, pointers, and the long type are 64 bits in length. The int type, however, is 32 bits long. The Alpha can access and manipulate 64 bits, one word at a time.
处理器的通用寄存器 (GPR) 的大小等于其字长。例如,给定架构中组件的宽度,内存总线通常至少与字大小一样宽。通常,至少在 Linux 支持的体系结构中,内存地址空间等于字大小[2]。因此,指针的大小等于字的大小。另外,C 类型 long 的大小等于字大小,而 int 类型的大小有时小于字大小。例如,Alpha 的字长为 64 位。因此,寄存器、指针和 long 类型的长度为 64 位。但是,int 类型的长度为 32 位。Alpha 可以访问和操作 64 位,一次一个字。
Further read : http://www.makelinux.com/books/lkd2/ch19lev1sec2
回答by SLaks
WORDin Windows APIs means 2 bytes.
WORD在 Windows API 中意味着 2 个字节。
It was originally used to refer to the pointer-size (as in a CPU with a word length of 16 bits).
The Windows APIs used it in typedefsback in (and before) Windows 3.1 (which only supported 16-bit machines), so the meaning cannot change anymore.
它最初用于指指针大小(如在字长为 16 位的 CPU 中)。
Windows APItypedefs在(和之前)Windows 3.1(仅支持 16 位机器)中使用它,因此其含义不能再改变。
回答by Devolus
WORDis probably from some older code and usually meant 16-bits, while DWORDusually means 32-bits. If you are unsure you should check your code though, because they have to be defined somewhere.
WORD可能来自一些较旧的代码,通常表示 16 位,而DWORD通常表示 32 位。如果你不确定你应该检查你的代码,因为它们必须在某处定义。
WORDstems from machine word which size was hardware dependent.
WORD源于机器字,其大小取决于硬件。

