Cardinal/fr

From Lazarus wiki
Revision as of 10:48, 20 April 2014 by E-ric (talk | contribs) (Created page with "Cardinal is an integer type defined as an alias for DWord under a 32bit plateform. Like the DWord (double word) type it's a 32 bit data interpreted as an unsigned integer. As ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Cardinal is an integer type defined as an alias for DWord under a 32bit plateform. Like the DWord (double word) type it's a 32 bit data interpreted as an unsigned integer. As it's only used on 32 bit systems, its minimal value is 0x0000000 and its maximal value 0xFFFFFFFF.

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

 var
   AnAddress: Cardinal;
   AnObject: TObject;
 begin
   AnAddress := Cardinal(Self);
   with TObject(AnAddress) do
   begin
     // AnAddress is casted as a TObject.
   end;
 end;
 

However, because of the 32 and 64 bits little endian systems, using the Cardinal type is not recommended anymore for memory/pointer operations/arithmetic. Actually it's rather recommended to use NativeInt or NativeUInt types. These types will match to a CPU register wide data which can be used to encode a memory address and so will be always valid. For example under a 64bit 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