Difference between revisions of "Data type"

From Free Pascal wiki
Jump to navigationJump to search
([cardinal]] - an unsigned whole number)
(→‎Signed types: Make the "LongInt" point to the page of "Longint")
 
(11 intermediate revisions by 8 users not shown)
Line 1: Line 1:
 
{{Data type}}
 
{{Data type}}
  
A '''data type''' is a classification of a variable or constant.  There are certain data types that are predefined by any Pascal compiler (because you need them to make everything else).  These are:
+
=General=
  
* [[Byte|byte]] - an unsigned number in the range 0 to 255
+
This page provides an assortment of data types in Free Pascal.
* [[Char|char]] - Single character
 
* [[Integer|integer]] - a whole number.  FPC currently uses 4 bytes for integers
 
* [[real]] - a number which may have a decimal point and possibly an exponent
 
* [[cardinal]] - an unsigned  whole number,ie it must be positiv
 
* [[set]] - a collection of related elements; size depends on number of elements
 
* [[Pointer|pointer]] - a reference to a location in memory, generally used for dynamic variables
 
* [[record]] - a combination of the above data types collected together
 
* [[object]] - a hybrid entity that may contain data and procedures to manipulate that data
 
  
Other data types are generally made with some combination of the above. FPC adds additional data types.
+
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.
 +
 
 +
=Integer types=
 +
 
 +
==Unsigned types==
 +
 
 +
[[Data field]]s 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 field]]s of signed integral types can contain positive '''and''' negative integral numbers.
 +
 
 +
* [[Int8]] - Range: (-128 .. 127)
 +
* [[Shortint|ShortInt]] - Range: (-128 .. 127)
 +
* [[Int16]] - Range: (-32768 .. 32767)
 +
* [[Smallint|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|LongInt]] - Range: (-2147483648 .. 2147483647)
 +
* [[Int64]] - Range: (-9223372036854775808 .. 9223372036854775807)
 +
 
 +
=Floating-point types=
 +
 
 +
[[Data field]]s of a floating-point type can contain:
 +
 
 +
# positive '''and''' negative integral numbers with possible round-off errors.
 +
# 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 field]]s of boolean type contain truth values.
 +
 
 +
* [[Boolean]] - Range: (True, False), 8 Bit
 +
* [[Bytebool|ByteBool]] - Range: (True, False), 8 Bit
 +
* [[Wordbool|WordBool]] - Range: (True, False), 16 Bit
 +
* [[Longbool|LongBool]] - Range: (True, False), 32 Bit
 +
 
 +
=Enumeration types=
 +
 
 +
[[Data field]]s of an enumeration type are "lists" (enumerations...) of integral unsigned constants.
 +
 
 +
* [[Enum Type]] - Range: (integral data types)
 +
 
 +
=Char types=
 +
 
 +
==Char types with single byte encoding==
 +
 
 +
* [[Char]] - Constant length: 1 byte, representation: 1 character.
 +
* [[Shortstring|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|AnsiString]] - No 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]].
 +
 
 +
== Char types with multi byte encoding==
 +
 
 +
(The encoding with 2 or 4 bytes is system dependent.<br>
 +
 
 +
* [[WideChar]] - Constant length: 2 or 4 bytes, representation: 1 character.
 +
* [[Widestring|WideString]] - No length restriction.
 +
* [[Pwidechar|PWideChar]] - Pointer to a null-terminated wide string without length restriction.
 +
* [[Unicodechar|UnicodeChar]] - Constant length: 2 or 4 bytes, representation: 1 character.
 +
* [[Unicodestring|UnicodeString]] - No 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]].
 +
 
 +
=Variant types=
 +
 
 +
*[[Variant]]
 +
*[[Olevariant]]
 +
 
 +
=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|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=
 +
 
 +
* [[subrange types]] are a subset of a base type.
 +
 
 +
=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 =
 +
 
 +
* [[Pascal basics]]

Latest revision as of 17:06, 29 August 2021

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