From Free Pascal wiki
Revision as of 13:40, 24 November 2020 by Arent (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Deutsch (de) English (en) français (fr) русский (ru)

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.

navigation bar: data types
simple data types

boolean byte cardinal char currency double dword extended int8 int16 int32 int64 integer longint real shortint single smallint pointer qword word

complex data types

array class object record set string shortstring