Restrictions on packed types?_(re)

Mon, 10 Feb 1997 15:16:12 +0100 (MET)


According to Jakob Heinemann:
> I read somewhere that GPC actually doesn't pack things in types which
> are
> declared as PACKED. Is this true? What about packed array's of char,
> i.e.
> non-varying strings?

It is true, but it only affects things which are smaller than one byte
or structures containings things which should be aligned on a 2- or
4-byte boundary.

One example:

    Type
      ByteInt = __byte__ Integer;
      Byte = __unsigned__ ByteInt;

    Var
      AOC: array [ 1..100 ] of Char;
      PAOC: packed array [ 1..100 ] of Char;
      AOBoo: array [ 1..100 ] of Boolean;
      PAOBoo: packed array [ 1..100 ] of Boolean;
      AOBy: array [ 1..100 ] of Byte;
      PAOBy: packed array [ 1..100 ] of Byte;

all have 100 bytes (while PAOBoo should have ( 100 + 7 ) div 8 bytes), and

    MyRec: record
      B: Byte;
      C: Char;
      I: Integer;
    end (* MyRec *);

has 8 bytes, not 6.

\begin{sigh}
  When we say that GPC "does not pack" this means about the same as
  what Borland means when they claim that Borland Pascal "always packs".
  The only difference is that Borland Pascal does not care about 32-bit
  alignment and thus often produces records of smaller size - at the
  expense of loss of speed.
\end{sigh}

Hope this helps,

    Peter

  Dipl.-Phys. Peter Gerwinski, Essen, Germany, free physicist and programmer
peter.gerwinski@uni-essen.de - http://home.pages.de/~peter.gerwinski/ [970201]
       maintainer GNU Pascal - http://home.pages.de/~gnu-pascal/ [970125]


Peter Gerwinski (peter@agnes.dida.physik.uni-essen.de)

HTML conversion by Lluís de Yzaguirre i Maura
Institut de Lingüística Aplicada - Universitat "Pompeu Fabra"
e-mail: de_yza@upf.es