Pascal --> C question

Scott Schwartz schwartz at gondor.cs.psu.edu
Fri Mar 11 11:41:57 AEST 1988


swarbric at tramp.Colorado.EDU (Frank Swarbrick) writes:
>:
>:Except that the useful ones are never that easy.  One of my favorites:
>:	bitstring: packed array[0..1023] of boolean;
>:In C you have to do bit-fiddling by hand to get the same effect.
>:
>typedef char bool;
>bool bitstring[1024];
>
>Or does the "packed" thing in Pascal have some special meaning?  I never could
>figure out what the difference between a packed array and a regular array was.

The "packed" thing has a special meaning.  I can't quote you from the
ANSI or ISO standards offhand, but the idea is that the compiler is
supposed to arrange that the packed structure takes up a minimal amount
of space (probably subject to some alignment restrictions).  So in the
example I gave each boolean would take up one bit, and there would be
1024 of them, the whole array taking up 128 bytes.  Unpacked, each
boolean would take up one, two, or maybe four (depending on how unlucky
you are) bytes.

In (I can't believe I'm about to type this, but...) the hypothetical
"D" language it would be nice to be able to say

	typedef bool bit;
	bool bitstring[1024];

but, alas....



-- Scott Schwartz                       | Your array may be without head or     
        schwartz at gondor.cs.psu.edu      | tail, yet it will be proof against
                                        | defeat.  -- Sun Tzu, "The Art of War"



More information about the Comp.lang.c mailing list