harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Geir Magnusson Jr." <ge...@apache.org>
Subject Re: opinions on structure packing in C?
Date Wed, 05 Oct 2005 18:28:39 GMT

On Oct 5, 2005, at 9:44 AM, Tim Ellison wrote:

> Geir Magnusson Jr. wrote:
>> I'm working with Dan's bootVM to get to run on Windows, and have been
>> thinking about the use of -fpack-struct vs #pragm pack() vs just not
>> packing and writing code that is a little slower, and a little more
> I'd dispute that packing always produces faster code, but...

I wasn't suggesting the packing itself made things faster, but if a  
1000 field structure :b maps directly onto a buffer, memcpy() is your  

>> verbose, but seemingly more robust and maintainable due to less
>> information about context needed to avoid surprises.
>> I've reconfirmed that packing structs is deadly when you want to call
>> into standard libs
>> struct stat foo;
>> stat("foo.txt", &foo);
>> does some bizarre things :)
>> So how do people deal with this these days?  I know fashions change,
>> and I haven't done C in anger for > 6 years...  (I still have the
>> shakes when looking at it - I'm past the screaming stage...)
> Just use the compiler's default (ANSI) layout behavior, and then
> explicitly pack a struct using pragmas only where required -- usually
> for layout compatibility with an external binary.
> As you illustrate above, packing somebody else's struct definition can
> bring you into conflict with their binary's view of the world.

Yep - that's what I've done w/ bootJVM, and it works just fine so far..


Geir Magnusson Jr                                  +1-203-665-6437

View raw message