Word: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Word
| Old | New | Line | |
|---|---|---|---|
| 1 | + | A **word** is the processor’s native data unit. Modern consumer processors have a word width of [[64 bit|64 bits]]. | |
| 2 | + | ||
| 3 | + | ## Data type | |
| 4 | + | ||
| 5 | + | Most [[RTL|run-time libraries]] provide the native data type of a processor as the Pascal data type `word`. It is a subset of all whole numbers (non-negative integers) that can be represented by the processor’s natural data unit size. | |
| 6 | + | ||
| 7 | + | On a 64-bit architecture this means a `word` is an integer within the range $`[0,~2^{64}-1]`$. On a 32-bit architecture a `word` will be an integer in the range $`[0,~2^{32}-1]`$, and so on, respectively. | |
| 8 | + | ||
| 9 | + | In [[GNU Pascal]] a `word` is just an alias for [[Cardinal|cardinal]], which has the same properties regarding possible values. | |
| 10 | + | ||
| 11 | + | If a *signed* integer having the processor’s native size is wanted, the data type [[Integer|integer]] provides this functionality. | |
| 12 | + | ||
| 13 | + | ### FPC | |
| 14 | + | ||
| 15 | + | For source compatibility reasons, [[FPC]] defines `word` in the same way as Turbo Pascal and Delphi: the subrange data type `0..65535`. The `high` value `65535` is $`2^{16}-1`$. Thus a [`system.word`](https://www.freepascal.org/docs-html/rtl/system/word.html) occupies two bytes of space. Subrange data types are stored in a quantity that serves best the goals of performance and memory efficiency. | |
| 16 | + | ||
| 17 | + | The processor’s native word size, as defined above, corresponds to different types depending on the purpose you want to use it for: | |
| 18 | + | ||
| 19 | + | - the (as of 2022 still undocumented) [`system.ALUSint`](https://www.freepascal.org/docs-html/rtl/system/alusint.html) and [`system.ALUUint`](https://www.freepascal.org/docs-html/rtl/system/aluuint.html) types correspond to the native word size used by the processor’s ALU (arithmetic and logical unit), as defined at the beginning of this page. In general, this type should not be used in high level code. Instead, choose a data type based on the values it should be able to represent, as this is safer and more portable. It is the compiler’s job to generate optimal code. | |
| 20 | + | - [`system.CodePtrUInt`](https://www.freepascal.org/docs-html/rtl/system/codeptruint.html) corresponds to the size of pointers to code, such as the address of a [[Procedure|procedure]]. This can be different from a pointer to data, e. g. on targets that support multiple [[DOS|memory models]]. | |
| 21 | + | - [`system.PtrUInt`](https://www.freepascal.org/docs-html/rtl/system/ptruint.html) corresponds to the size of pointers to data. | |
| 22 | + | ||
| 23 | + | On many platforms, all of these types have the same size, but it is not the case everywhere. | |
| 24 | + | ||
| 25 | + | In FPC a [[Smallint|smallInt]] has the same size as a `word`, but is signed. | |
| 26 | + | ||
| 27 | + | --- | |
| 28 | + | *From the Free Pascal wiki, page "Word", as it stood on 2022-09-08 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
