Difference between revisions of "Cardinal"
(spelling and slight rewording) |
|||
Line 1: | Line 1: | ||
{{Cardinal}} | {{Cardinal}} | ||
− | Cardinal is an integer type defined as an alias for DWord under a | + | 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. As it's only used on 32-bit systems, its minimal value is 0x0000000 and its maximal value 0xFFFFFFFF (4,294,967,295). |
− | On | + | On x86 systems Cardinal type is often used to hold a memory address, like a pointer: |
<code> | <code> | ||
Line 18: | Line 18: | ||
</code> | </code> | ||
− | However, because of | + | 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}} | {{Data types}} |
Revision as of 15:10, 9 July 2016
│
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. As it's only used on 32-bit systems, 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:
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 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.
simple data types |
|
---|---|
complex data types |