Re: Packing for __nogc classes
From: Doug Harrison [MVP] (dsh_at_mvps.org)
Date: 02/22/04
- Next message: .: "Re: Message 36? WM_????"
- Previous message: Bonj: "Re: Message 36? WM_????"
- In reply to: Edward Diener: "Re: Packing for __nogc classes"
- Next in thread: Edward Diener: "Re: Packing for __nogc classes"
- Reply: Edward Diener: "Re: Packing for __nogc classes"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 22 Feb 2004 13:39:02 -0600
Edward Diener wrote:
>The reason for this post has to do with a potential common problem pre-.NET
>having to do with packing of classes/structures. If the programmer/creator
>of a struct/class does not specifically set a packing size, via the #pragma
>pack directive, when the compiler saw the header file it would apply
>whatever the packing was in the IDE ( or command-line ). This could lead to
>ABI problems if a library was built with a particular packing for a
>class/structure and the end-user of that library decided to change the
>global packing in the IDE ( or command-line ) to some other value. The
>solution to this problem was for the programmer/creator to set the packing
>for the class.structure in the header file for the class/structure via
>"#pragma pack". Then the compiler would honor this directive by overriding
>the end-user's global packing for that particular class/struct and all would
>be well with no ABI problem occurring. Every 3rd party implementation which
>distributed C++ header files/library would of course use the "#pragma pack"
>method to assure that no ABI problem would occur.
I think that's backwards. The real solution is to never use /Zp but instead
use #pragma pack on structs only as necessary. If you expect everybody to
use #pragma pack in order to write /Zp-neutral headers, you've effectively
made #pragma pack part of the language, which is, to put it mildly, not a
good thing. I'd personally like to see /Zp abolished, and I'd like #pragma
pack to generate warnings when its effects penetrate #includes, both coming
or going. An exception to this latter rule could be made for the
<pshpackN.h> and <poppack.h> Windows headers. BTW, the Windows headers are
not all /Zp-neutral.
-- Doug Harrison Microsoft MVP - Visual C++
- Next message: .: "Re: Message 36? WM_????"
- Previous message: Bonj: "Re: Message 36? WM_????"
- In reply to: Edward Diener: "Re: Packing for __nogc classes"
- Next in thread: Edward Diener: "Re: Packing for __nogc classes"
- Reply: Edward Diener: "Re: Packing for __nogc classes"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|