From Free Pascal wiki
Jump to: navigation, search

Deutsch (de) English (en) français (fr)

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).

On x86 systems Cardinal type is often used to hold a memory address, like a pointer:

    anAddress: Cardinal;
    anObject: TObject;
    anAddress := Cardinal(Self);
    with TObject(anAddress) do
      // anAddress is casted as a TObject.

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.

Data Types
Simple Data Types Boolean | Byte | Cardinal | Char | Currency | Extended | Int64 | Integer | Longint | Pointer | Real | Shortint | Smallint | Word
Complex Data Types Array | Class | Record | Set | String | ShortString