Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the point WORD type in C?

Tags:

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?

like image 811
Nealon Avatar asked May 31 '13 18:05

Nealon


2 Answers

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.

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.

Further read : http://www.makelinux.com/books/lkd2/ch19lev1sec2

like image 124
Oscar Avatar answered Oct 06 '22 05:10

Oscar


WORD in Windows APIs means 2 bytes.

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 typedefs back in (and before) Windows 3.1 (which only supported 16-bit machines), so the meaning cannot change anymore.

like image 25
SLaks Avatar answered Oct 06 '22 04:10

SLaks