[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 9.222 record

### Synopsis

In type definitions:

    record type identifier = record
      field identifier: type definition
      ...
      field identifier: type definition
    end;

or, with a variant part,

    record type identifier = record
      field identifier: type definition
      ...
      field identifier: type definition
      case bar: variant type of
        selector: (field declarations);
        selector: (field declarations);
        ...
    end;

or, without a variant selector field,

    record type identifier = record
      field identifier: type definition
      ...
      field identifier: type definition
      case variant type of
        selector: (field declarations);
        selector: (field declarations);
        ...
    end;

### Description

The reserved word ``record'` starts the definition of a new record type.

Records can be ``packed'` to save memory usage at the expense of speed.

The variants of a variant record may -- but are not required to -- share one location in memory (inside the record).

Sometimes variant records are used to emulate type casting in ISO-7185 Pascal. This is in fact a violation of the standard and not portable. There is intentionally no possibility in ISO-7185 Pascal to emulate type casting.

### Conforming to

The reserved word ``record'` and record types are defined in ISO-7185 Pascal.

According to ISO Pascal, the variant type must be an identifier. GNU Pascal, like UCSD and Borland Pascal, also allows a subrange here.

Subranges in the variant fields, e.g. `case Integer of 2 .. 5`, are a GPC extension.

### Example

    program RecordDemo;

    type
      FooPtr = ^Foo;

      Foo = record
        Bar: Integer;
        NextFoo: fooPtr;
        case Choice: 1 .. 3 of
          1: (a: Integer);  { These three choices may share }
          2: (b: Real);     { one location in memory. }
          3: (c: Char;
              d: Boolean);
      end;

      SmallFoo = packed record
        b: 0 .. 3;
        a: Integer (5);
        r: Boolean
      end;  { needs 1 byte }

    var
      f: Foo;

    begin
      f.b := 3.14;
      WriteLn (f.a)  { yields some strange number which is part of the   }
                     { internal representation of the real number `f.b'. }
    end.

### See also

section 9.188 packed, section 8.1.7.4 case Statement

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

This document was generated by Frank Heckenbach on May, 10 2002 using texi2html