PACKED ARRAYS (was Re: Has class become a reserved word?)

Frank Heckenbach frank at g-n-u.de
Sat Mar 17 00:11:40 CET 2001


J. David Bryan wrote:

> On 16 Mar 2001, at 2:56, Frank Heckenbach wrote:
> 
> > ...but since we've decided to do packing at all, we should also do it
> > "reasonable"... 
> 
> One question is whether it is more "reasonable" to pack to bit or byte 
> level.  That is, should:
> 
>   a : packed array [1..3] of 0..31;
> 
> ...take two bytes or three?  (It will take two if it's packed to the bit 
> level, where each element uses five bits, or three if it's packed to the 
> byte level, where each element uses eight bits.  Presumably, an equivalent 
> unpacked array would use twelve bytes, where each element uses four bytes 
> if the "natural" word size is 32 bits.)
>
> I suppose packing would be most "reasonable" if it packed to the bit level, 
> as one could always explicitly pad to a byte boundary if desired, whereas 
> it would take a fair programming effort (i.e., shifts and masks) to effect 
> bit packing if GPC only packed to the byte level.  I've used compilers that 
> took the opposite approaches, and it seemed to me to be easier and cleaner 
> from a user's programming perspective to work with the compiler that packed 
> to the bit level.

Agreed.

> Of course, that is easy for me to say, as I have no idea how hard it would 
> be to implement either scheme in GPC!  ;-)

GPC implements bit-level packing already (with `packed 0..13'), so I
think it's only a matter of setting some flag in the right place in
the compiler...

Frank

-- 
Frank Heckenbach, frank at g-n-u.de, http://fjf.gnu.de/
GPC To-Do list, latest features, fixed bugs:
http://agnes.dida.physik.uni-essen.de/~gnu-pascal/todo.html




More information about the Gpc mailing list