Next: , Previous: Pack, Up: Reference



packed

Synopsis

Description

packed is a reserved word. According to ISO 7185 Pascal it can precede array and record type definitions to indicate that memory usage should be minimized for variables of this type, possibly at the expense of loss of speed.

As a GNU Pascal extension, packed can also be applied to Subrange Types.

Conforming to

The reserved word packed is defined in ISO 7185 Pascal.

According to ISO standard, only packed arrays of char with lower bound 1 qualify as strings of fixed length. GNU Pascal neither requires packed nor the lower bound of 1 here.

Example

     program PackedDemo;
     
     type
       MonthInt = packed 1 .. 12;  { needs one byte }
       FastMonthInt = 1 .. 12;     { needs e.g. four bytes }
     
       FixString10 = packed array [1 .. 10] of Char;
       FoxyString10 = array [0 .. 9] of Char;
     
       Flags = packed array [1 .. 32] of Boolean;  { needs four bytes }
     
       Int15 = Integer attribute (Size = 15);
       DateRec = packed record
         Day: 1 .. 31;       { five bits }
         Month: MonthInt;    { four bits }
         Year: Int15         { 15 bits = -16384 .. 16383 }
       end;
     
       Dates = array [1 .. 1000] of DateRec;
     
     var
       S: FixString10;
       T: FoxyString10;
     
     begin
       S := 'Hello!';  { blank padded }
       WriteLn (S);
     
       T := 'GNU Pascal';  { GPC extension: this also works. }
       WriteLn (T)
     end.

DateRec has 24 bits = 3 bytes in total; Dates has 3000 bytes.

See also

Keywords, Pack, Unpack, SizeOf, AlignOf, BitSizeOf.