Difference between revisions of "Data type"

From Free Pascal wiki
Jump to navigationJump to search
(Deleted categories (all needed is in template))
Line 135: Line 135:
  
 
* [[Pascal basics]]
 
* [[Pascal basics]]
 
{{AutoCategory}}[[Category:Data types]]
 

Revision as of 21:33, 18 July 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