[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Edlug Archive Mar 2004 ]

RE: [edlug] OT: Linux-Windows datastructure exchange C++

> The MS equivalent is
>   #pragma pack
> This will presumably pack all the data structures within its scope. Do
> you know if theres a way to be more selective over which 
> datastructures
> are packed.

I think you're supposed to do this:

#pragma pack(push)
#pragma pack(1)
struct Foo {...};
struct Bar {...};
#pragma pack(pop)

(maybe those 1st two can be combined to #pragma pack(push,1)

NB It's important to push and pop rather than just revert-to-default
or #include nesting WILL bite you at some point.

There is some extra stuff to provide named identifiers for the state,
but you'll have to check the MSDN docs for that.

I would follow up with whole load of assert(sizeof(Foo)==32)
type checks first thing on startup (and probably check individual
member offsets too) just to be sure stuff is where you think it should be.


Tim Day
Senior Software Engineer
Voxar Limited
Edinburgh - Corporate Headquarters | Boston
Bonnington Bond, 2 Anderson Place, Edinburgh EH6 5NP, UK
Tel: +44 (0) 131 472 4792 Fax: +44 (0) 131 472 4799
Email: tim.day@xxx.xxx.xxx Web: www.voxar.com
Registered in Scotland No. 145641 Registered Office as above.

This email is sent subject to the legal requirements set out at
You can find the EdLUG mailing list FAQ list at:

This archive is kept by wibble@morpheux.org.DONTSPAMME