Cardinal: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Cardinal
| Old | New | Line | |
|---|---|---|---|
| 1 | + | **Cardinal** is an integer type defined as an alias for [[DWord]] under a 32-bit platform. Like the DWord (double word) type it's 32 bits and interpreted as an unsigned integer. Its minimal value is 0x0000000 and its maximal value 0xFFFFFFFF (4,294,967,295). | |
| 2 | + | ||
| 3 | + | On x86 systems Cardinal type is often used to hold a memory address, like a pointer: | |
| 4 | + | ||
| 5 | + | ``` pascal | |
| 6 | + | var | |
| 7 | + | anAddress: Cardinal; | |
| 8 | + | anObject: TObject; | |
| 9 | + | begin | |
| 10 | + | anAddress := Cardinal(Self); | |
| 11 | + | with TObject(anAddress) do | |
| 12 | + | begin | |
| 13 | + | // anAddress is casted as a TObject. | |
| 14 | + | end; | |
| 15 | + | end; | |
| 16 | + | ``` | |
| 17 | + | ||
| 18 | + | However, because of 32 and 64 bit little endian systems, using the Cardinal type is ***not recommended*** anymore for memory/pointer operations/arithmetic. It's recommended to use **NativeInt** or **NativeUInt** types instead. These types will match the width of the CPU registers which can be used to encode a memory address and so will always be the right size. For example under a 64b-bit OS, a NativeUInt will be like a UInt64 or a QuadWord and under a 32-bit OS, a NativeUInt will be like a DWord or a Cardinal. | |
| 19 | + | ||
| 20 | + | --- | |
| 21 | + | *From the Free Pascal wiki, page "Cardinal", as it stood on 2020-11-24 after a change by Arent, 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).* |
