[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Interview



Bert Peers wrote:

> > We used structs in both (Win32 and Linux) versions of Quadra, and both
> > platforms do word alignment. There is a compiler pragma that works on
> > both Visual C++ and gcc/egcs, "#pragma pack(1)" to start packing and
> > "#pragma pack()" to stop.
> 
> Huh ?  I thought it was the other way around :)  From MSDN :
> 
> When you use #pragma pack(n), where n is 1, 2, 4, 8, or 16,
> each structure member after the first is stored on the smaller
> member type or n-byte boundaries. If you use #pragma pack
> without an argument, structure members are packed to the
> value specified by /Zp. The default /Zp packing size is /Zp8.
> 
> So pack (1) would disable packing because it "packs" to 1 byte,
> and pack () would restore whatever you had by default, which is
> 8 bytes for VC++.  Or am I missing something :)

Yes, exactly. pack(1) does byte-align, then pack() "stops" packing, ie
goes back to the default of the compiler.

Or maybe you were confused by the first sentence ("and both platforms do
word alignment")? What I meant is that the default is some alignment
that is not packed (preventing the kind of fread that Philipp
described). The pragma enabled us to read the whole struct in a single
read operation.

-- 
Pierre Phaneuf
Ludus Design, http://ludusdesign.com/
"First they ignore you. Then they laugh at you.
Then they fight you. Then you win." -- Gandhi