Difference between revisions of "Data type"

From Lazarus wiki
Jump to navigationJump to search
(Translation of the German article for a much more detailed overview.)
m (Fixed wiki markup; added see also)
Line 1: Line 1:
 
{{Data type}}
 
{{Data type}}
<br>
+
 
 
=General=
 
=General=
This page provides an assortment of data types in Free Pascal.<br>
+
 
A '''data type''' is a template for a [[Data field|data field]].<br>
+
This page provides an assortment of data types in Free Pascal.
The data type of a field defines how the compiler and processor interpret it's content.<br>
+
 
 +
A '''data type''' is a template for a [[Data field|data field]].
 +
 
 +
The data type of a field defines how the compiler and processor interpret it's content.
 +
 
 
The visibility of a [[Data field|data field]] depends on the location of it's declaration.
 
The visibility of a [[Data field|data field]] depends on the location of it's declaration.
<br>
 
<br>
 
  
 
=Integer types=
 
=Integer types=
 +
 
==Unsigned types==
 
==Unsigned types==
 +
 
[[Data field]]s of unsigned integral types can only contain '''positive''' integral numbers.
 
[[Data field]]s of unsigned integral types can only contain '''positive''' integral numbers.
 +
 
* [[UInt8]] - Range: (0 .. 255)
 
* [[UInt8]] - Range: (0 .. 255)
 
* [[Byte]] - Range: (0 .. 255)
 
* [[Byte]] - Range: (0 .. 255)
Line 23: Line 28:
 
* [[UInt64]] - Range:  (0 .. 18446744073709551615)
 
* [[UInt64]] - Range:  (0 .. 18446744073709551615)
 
* [[QWord]] - Range:  (0 .. 18446744073709551615)
 
* [[QWord]] - Range:  (0 .. 18446744073709551615)
<br>
 
  
 
==Signed types==
 
==Signed types==
 +
 
[[Data field]]s of signed integral types can contain positive '''and''' negative integral numbers.
 
[[Data field]]s of signed integral types can contain positive '''and''' negative integral numbers.
 +
 
* [[Int8]] - Range: (-128 .. 127)
 
* [[Int8]] - Range: (-128 .. 127)
 
* [[Shortint|ShortInt]] - Range: (-128 .. 127)
 
* [[Shortint|ShortInt]] - Range: (-128 .. 127)
Line 36: Line 42:
 
* [[Longint]] - Range: (-2147483648 .. 2147483647)
 
* [[Longint]] - Range: (-2147483648 .. 2147483647)
 
* [[Int64]] - Range: (-9223372036854775808 .. 9223372036854775807)
 
* [[Int64]] - Range: (-9223372036854775808 .. 9223372036854775807)
<br>
 
  
 
=Floating-point types=
 
=Floating-point types=
 +
 
[[Data field]]s of a floating-point type can contain:
 
[[Data field]]s of a floating-point type can contain:
 +
 
# positive '''and''' negative integral numbers with possible round-off errors.
 
# positive '''and''' negative integral numbers with possible round-off errors.
 
# positive '''and''' negative floating-point numbers.
 
# positive '''and''' negative floating-point numbers.
<br>
+
 
 
* [[Single]] - Range: (1.5E-45 .. 3.4E38)
 
* [[Single]] - Range: (1.5E-45 .. 3.4E38)
 
* [[Real]] - Range: depends on the platform.
 
* [[Real]] - Range: depends on the platform.
Line 50: Line 57:
 
* [[Comp]] - Range: (-2E64+1 .. 2E63-1)
 
* [[Comp]] - Range: (-2E64+1 .. 2E63-1)
 
* [[Currency]] - Range: (-922337203685477.5808 .. 922337203685477.5807)
 
* [[Currency]] - Range: (-922337203685477.5808 .. 922337203685477.5807)
<br>
 
  
 
=Boolean types=
 
=Boolean types=
 +
 
[[Data field]]s of boolean type contain truth values.
 
[[Data field]]s of boolean type contain truth values.
 +
 
* [[Boolean]] - Range: (True, False), 8 Bit
 
* [[Boolean]] - Range: (True, False), 8 Bit
 
* [[Bytebool|ByteBool]] - Range: (True, False), 8 Bit
 
* [[Bytebool|ByteBool]] - Range: (True, False), 8 Bit
 
* [[Wordbool|WordBool]] - Range: (True, False), 16 Bit
 
* [[Wordbool|WordBool]] - Range: (True, False), 16 Bit
 
* [[Longbool|LongBool]] - Range: (True, False), 32 Bit
 
* [[Longbool|LongBool]] - Range: (True, False), 32 Bit
<br>
+
 
 
=Enumeration types=
 
=Enumeration types=
 +
 
[[Data field]]s of an enumeration type are "lists" (enumerations...) of integral unsigned constants.
 
[[Data field]]s of an enumeration type are "lists" (enumerations...) of integral unsigned constants.
 +
 
* [[Enum Type]] - Range: (integral data types)
 
* [[Enum Type]] - Range: (integral data types)
<br>
+
 
 
=Char types=
 
=Char types=
 +
 
==Char types with single byte encoding==
 
==Char types with single byte encoding==
 +
 
* [[Char]] - Constant length: 1 byte, representation: 1 character.
 
* [[Char]] - Constant length: 1 byte, representation: 1 character.
 
* [[Shortstring|ShortString]] - Maxmimum length: 255 characters.
 
* [[Shortstring|ShortString]] - Maxmimum length: 255 characters.
Line 71: Line 83:
 
* [[Ansistring|AnsiString]] - No length restriction.
 
* [[Ansistring|AnsiString]] - No length restriction.
 
* [[Pansichar|PAnsiChar]] - Pointer to a null-terminated string without length restriction.
 
* [[Pansichar|PAnsiChar]] - Pointer to a null-terminated string without length restriction.
 +
 
See the overview of the different [[Character and string types|character and string types]].
 
See the overview of the different [[Character and string types|character and string types]].
<br>
 
  
 
== Char types with multi byte encoding==
 
== Char types with multi byte encoding==
 +
 
(The encoding with 2 or 4 bytes is system dependent.<br>
 
(The encoding with 2 or 4 bytes is system dependent.<br>
 +
 
* [[Widechar|WideChar]] - Constant length: 2 or 4 bytes, representation: 1 character.
 
* [[Widechar|WideChar]] - Constant length: 2 or 4 bytes, representation: 1 character.
 
* [[Widestring|WideString]] - No length restriction.
 
* [[Widestring|WideString]] - No length restriction.
Line 82: Line 96:
 
* [[Unicodestring|UnicodeString]] - No length restriction.
 
* [[Unicodestring|UnicodeString]] - No length restriction.
 
* [[Punicodechar|PUnicodeChar]] - Pointer to a null-terminated Unicode string without length restriction.
 
* [[Punicodechar|PUnicodeChar]] - Pointer to a null-terminated Unicode string without length restriction.
 +
 
See the overview of the different [[Character and string types|character and string types]].
 
See the overview of the different [[Character and string types|character and string types]].
<br>
 
  
 
=Variant types=
 
=Variant types=
 +
 
*[[Variant]]
 
*[[Variant]]
 
*[[Olevariant]]
 
*[[Olevariant]]
<br>
+
 
 
=Constants=
 
=Constants=
 +
 
*Untyped constants
 
*Untyped constants
 
**[[Const]] - Only simple data types can be used.
 
**[[Const]] - Only simple data types can be used.
Line 96: Line 112:
 
*Resource Strings
 
*Resource Strings
 
**[[Resourcestring|Resourcestring]] - Used for localisation (not available in all compiler modes).
 
**[[Resourcestring|Resourcestring]] - Used for localisation (not available in all compiler modes).
<br>
 
  
 
=Structural types=
 
=Structural types=
 +
 
* [[Array]] - The size of the array depends on the type and the number of elements it contains.
 
* [[Array]] - The size of the array depends on the type and the number of elements it contains.
 
* [[Record]] - A combination of multiple data types.
 
* [[Record]] - A combination of multiple data types.
 
* [[Set]] - A set of elements of an ordinal type; the size depends on number of elements it contains.
 
* [[Set]] - A set of elements of an ordinal type; the size depends on number of elements it contains.
<br>
 
  
 
=Subrange types=
 
=Subrange types=
 +
 
* [[subrange types]] are a subset of a base type.
 
* [[subrange types]] are a subset of a base type.
<br>
 
  
 
=Pointer=
 
=Pointer=
 +
 
* [[Pointer]] - The size depends on the processor type.
 
* [[Pointer]] - The size depends on the processor type.
<br>
+
 
 
=Classes and objects=
 
=Classes and objects=
 +
 
* [[Object]] - Developed under Turbo Pascal 5.5 for DOS and the precursor of class.
 
* [[Object]] - Developed under Turbo Pascal 5.5 for DOS and the precursor of class.
 
* [[Class]] - Developed under Delphi 1.0 for Windows and the successor of object.
 
* [[Class]] - Developed under Delphi 1.0 for Windows and the successor of object.
<br>
+
 
<br>
+
= See also =
 +
 
 +
* [[Pascal basics]]
 +
 
 
{{AutoCategory}}[[Category:Data types]]
 
{{AutoCategory}}[[Category:Data types]]

Revision as of 12:04, 16 January 2020

Deutsch (de) English (en) español (es) français (fr) Bahasa Indonesia (id) italiano (it) русский (ru)

General

This page provides an assortment of data types in Free Pascal.

A data type is a template for a data field.

The data type of a field defines how the compiler and processor interpret it's content.

The visibility of a data field depends on the location of it's declaration.

Integer types

Unsigned types

Data fields of unsigned integral types can only contain positive integral numbers.

  • UInt8 - Range: (0 .. 255)
  • Byte - Range: (0 .. 255)
  • UInt16 - Range: (0 .. 65535)
  • Word - Range: (0 .. 65535)
  • NativeUInt - Range: depends on the processor type.
  • DWord - is equivalent to Longword.
  • Cardinal - is equivalent to Longword.
  • UInt32 - Range: (0 .. 4294967295)
  • Longword - Range: (0 .. 4294967295)
  • UInt64 - Range: (0 .. 18446744073709551615)
  • QWord - Range: (0 .. 18446744073709551615)

Signed types

Data fields of signed integral types can contain positive and negative integral numbers.

  • Int8 - Range: (-128 .. 127)
  • ShortInt - Range: (-128 .. 127)
  • Int16 - Range: (-32768 .. 32767)
  • SmallInt - Range: (-32768 .. 32767)
  • Integer - Range: is equivalent either to Smallint or Longint (for 16 respectively 32 bit processors).
  • Int32 - Range: (-2147483648 .. 2147483647)
  • NativeInt - Range: depends on the processor type.
  • Longint - Range: (-2147483648 .. 2147483647)
  • Int64 - Range: (-9223372036854775808 .. 9223372036854775807)

Floating-point types

Data fields of a floating-point type can contain:

  1. positive and negative integral numbers with possible round-off errors.
  2. positive and negative floating-point numbers.
  • Single - Range: (1.5E-45 .. 3.4E38)
  • Real - Range: depends on the platform.
  • Real48 - Range: 2.9E-39 .. 1.7E38
  • Double - Range: (5.0E-324 .. 1.7E308)
  • Extended - Range: depends on the platform.
  • Comp - Range: (-2E64+1 .. 2E63-1)
  • Currency - Range: (-922337203685477.5808 .. 922337203685477.5807)

Boolean types

Data fields of boolean type contain truth values.

  • Boolean - Range: (True, False), 8 Bit
  • ByteBool - Range: (True, False), 8 Bit
  • WordBool - Range: (True, False), 16 Bit
  • LongBool - Range: (True, False), 32 Bit

Enumeration types

Data fields of an enumeration type are "lists" (enumerations...) of integral unsigned constants.

Char types

Char types with single byte encoding

  • Char - Constant length: 1 byte, representation: 1 character.
  • ShortString - Maxmimum length: 255 characters.
  • String - Maxmimum length: Shortstring or Ansistring (depends in the used compiler switch).
  • PChar - Pointer to a null-terminated string without length restriction.
  • AnsiString - No length restriction.
  • PAnsiChar - Pointer to a null-terminated string without length restriction.

See the overview of the different character and string types.

Char types with multi byte encoding

(The encoding with 2 or 4 bytes is system dependent.

  • WideChar - Constant length: 2 or 4 bytes, representation: 1 character.
  • WideString - No length restriction.
  • PWideChar - Pointer to a null-terminated wide string without length restriction.
  • UnicodeChar - Constant length: 2 or 4 bytes, representation: 1 character.
  • UnicodeString - No length restriction.
  • PUnicodeChar - Pointer to a null-terminated Unicode string without length restriction.

See the overview of the different character and string types.

Variant types

Constants

  • Untyped constants
    • Const - Only simple data types can be used.
  • Typed constants
    • Const - Simple data types as well as records and arrays can be used.
  • Resource Strings
    • Resourcestring - Used for localisation (not available in all compiler modes).

Structural types

  • Array - The size of the array depends on the type and the number of elements it contains.
  • Record - A combination of multiple data types.
  • Set - A set of elements of an ordinal type; the size depends on number of elements it contains.

Subrange types

Pointer

  • Pointer - The size depends on the processor type.

Classes and objects

  • Object - Developed under Turbo Pascal 5.5 for DOS and the precursor of class.
  • Class - Developed under Delphi 1.0 for Windows and the successor of object.

See also