Delphi built-in data types and their memory sizes
Posted by jpluimers on 2019/08/21
Though 64-bit support was released back in 2011 with Delphi XE2, sometimes I forget which data type are native size and which keep their size no matter the compiler bitness (wiktionary/wikipedia).
This post was motivated by via [WayBack] Having started with Delphi before the Cardinal type was available (Or has it always? I can’t remember.) I routinely declare 32 bit unsigned variables as… – Thomas Mueller (dummzeuch) – Google+
The most simple distinction is between Win32 and Win64, but there are more non-32 bit platforms, so these do not suffice any more:
- [WayBack] 64-bit Windows Data Types Compared to 32-bit Windows Data Types – RAD Studio 10.2 Tokyo
- [WayBack] 64-bit Windows Data Types Compared to 32-bit Windows Data Types – RAD Studio XE3 (yes, that did not get documented in XE2)
The easiest for me are the below tables that only got introduced with Delphi 10.2 Tokyo: [WayBack] Delphi Data Types for API Integration – RAD Studio.
I have bolded the ones that change size.
Integer Data Types
Type Description Pointer Byte 8-bit unsigned integer PByte ShortInt 8-bit signed integer PShortInt Word 16-bit unsigned integer PWord SmallInt 16-bit signed integer PSmallInt Cardinal 32-bit unsigned integer PCardinal LongWord 32-bit unsigned integer (32-bit Windows, OSX32, 32-bit iOS, and Android platforms)
64-bit unsigned integer (64-bit iOS and 64-bit Linux platforms)PLongWord FixedUInt 32-bit unsigned integer PFixedUInt Integer 32-bit signed integer PInteger LongInt 32-bit signed integer (32-bit Windows, OSX32, 32-bit iOS, and Android platforms)
64-bit signed integer (64-bit iOS and 64-bit Linux platforms)PLongint FixedInt 32-bit signed integer PFixedInt UInt64 64-bit unsigned integer PUInt64 Int64 64-bit signed integer PInt64 NativeUInt 64-bit or 32-bit platform-dependent unsigned integer PNativeUInt NativeInt 64-bit or 32-bit platform-dependent signed integer PNativeInt Floating-point Data Types
Type Description Pointer Record Single Single precision floating-point value (4 bytes) PSingle TSingleRec Double Double precision floating-point value (8 bytes) PDouble TDoubleRec Extended Extended precision floating-point value (10 bytes on Win32, but 8 bytes on Win64)
See page about multi-device applications.PExtended TExtended80Rec Real Alias of Double N/A N/A
Earlier on, the
- Delphi XE2 documentation added a section describing the platform bitness effects in [WayBack] Simple Types (Delphi) – RAD Studio XE2
- Delphi XE8 documentation added more information for 64-bit iOS in [WayBack] Simple Types (Delphi) – RAD Studio XE8
- Delphi 10.2 Tokyo documentation added more information on other 64-bit POSIX platform in [WayBack] Simple Types (Delphi) – RAD Studio 10.2 Tokyo
Platform-dependent integer types
Type Platform Range Format Alias NativeInt 32-bit platforms -2147483648..2147483647
(-231..2^31-1)
Signed 32-bit Integer 64-bit platforms -9223372036854775808..9223372036854775807
(-263..263-1)
Signed 64-bit Int64 NativeUInt 32-bit platforms 0..4294967295
(0..232-1)
Unsigned 32-bit Cardinal 64-bit platforms 0..18446744073709551615
(0..264-1)
Unsigned 64-bit UInt64 LongInt 32-bit platforms and 64-bit Windows platforms -2147483648..2147483647
(-231..231-1)
Signed 32-bit Integer 64-bit POSIX platforms include iOS and Linux -9223372036854775808..9223372036854775807
(-263..263-1)
Signed 64-bit Int64 LongWord 32-bit platforms and 64-bit Windows platforms 0..4294967295
(0..232-1)
Unsigned 32-bit Cardinal 64-bit POSIX platforms include iOS and Linux 0..18446744073709551615
(0..264-1)
Unsigned 64-bit UInt64
- Note: 32-bit platforms include 32-bit Windows, 32-bit macOS, 32-bit iOS, iOS Simulator and Android.
Platform-Independent Integer Types
Platform-independent integer types always have the same size, regardless of what platform you use. Platform-independent integer types include ShortInt, SmallInt, LongInt, Integer, Int64, Byte, Word, LongWord, Cardinal, and UInt64.
Platform-independent integer types
Type Range Format Alias ShortInt -128..127
Signed 8-bit Int8 SmallInt -32768..32767
Signed 16-bit Int16 FixedInt -2147483648..2147483647
Signed 32-bit Int32 Integer -2147483648..2147483647
Signed 32-bit Int32 Int64 -9223372036854775808..9223372036854775807
(-263..263-1)
Signed 64-bit Byte 0..255
Unsigned 8-bit UInt8 Word 0..65535
Unsigned 16-bit UInt16 FixedUInt 0..4294967295
Unsigned 32-bit UInt32 Cardinal 0..4294967295
Unsigned 32-bit UInt32 UInt64 0..18446744073709551615
(0..264-1)
Unsigned 64-bit
Thomas Mueller blogged about the Alias
at [WayBack] Delphi LongWord is not always a 32 bit unsigned integer – twm’s blog (via[WayBack] Did you known that LongWord in Delphi is not (any longer) always a 32 bit unsigned integer? – Thomas Mueller (dummzeuch) – Google+) and I think he understood it backwards from what Embarcadero means:
NativeInt
on 32-bit platforms is an alias ofInteger
(so it is Signed 32-bit)NativeInt
on 64-bit platforms is an alias ofInt64
(so it is Signed 64-bit)
Some more fun links
For a lazy afternoon:
- History
- [WayBack] compiler construction – Why is creating a 64bit Delphi so hard? – Stack Overflow
- [WayBack] Getting Ready for Delphi 64
- [WayBack] The Oracle at Delphi: 64bit
- [WayBack] The Oracle at Delphi: More x64 assembler fun-facts–new assembler directives
- [WayBack] The Oracle at Delphi: x64 assembler fun-facts
- [WayBack] The Oracle at Delphi: Delphi check-in log entries of the day:
- [WayBack] The Oracle at Delphi: Divided and Confused
- [WayBack] The Oracle at Delphi: It’s my stack frame, I don’t care about your stack frame!
- [WayBack] The Oracle at Delphi: Delphi-Treff interview–In English
–jeroen
thaddy said
Of course the other powers of a negative value are also affected, here….
negation after, power first. Power renders always a positive value.
Thaddy said
Hm, really?(-2^63..2^63-1) that gives it a downward range of one! It should be -(2^63).. 2^63 – 1;
Stefan Glienke said
No, first exponentiation, then the sign. If the sign belongs to the base it has parantheses.
-2^4 = -16 but (-2)^4 = 16
thaddy said
That may be true in pascal notation, but not in mathematical notation. You are using implied pascal – which is wrong -, I use mathematics.
sglienke said
Those are math rules. See for example: https://math.stackexchange.com/questions/1382664/what-is-the-accepted-syntax-for-a-negative-number-with-an-exponent