Boost logo

Boost :

From: Sebastian Redl (sebastian.redl_at_[hidden])
Date: 2006-03-26 08:28:04


George M. Garner Jr. wrote:

>I am getting the following warning when I compile Regex 1-33-1 with VC2005
>for amd64 platform:
>
>--> # include BOOST_ABI_SUFFIX
>
>alignment changed after including header, may be due to missing #pragma
>
>pack(pop)
>
>Does anyone know what this is all about?
>
>
Sometimes, you'll need structures to be packed to a specific byte count,
for example when you're reading directly from a file, or simply to
ensure binary compatibility with something that's already defined.
The way to achieve this in VC++ is the #pragma pack instruction, used
like this:
#pragma pack (push, 1) // Align members at 1-byte boundaries (pack
tightly) and remember the old state.

struct packed
{
  char c;
  float f;
}; // sizeof(packed) == sizeof(char) + sizeof(float)

#pragma pack (pop) // restore old state

A very common way of placing these pragmas has been to include one
header file that contains the push pragma before doing your stuff, and
another containing the pop pragma after doing your stuff. This has two
advantages:
1) Only one place to change if you have several files with the same
alignment requirement. Since they all included the same header, you just
need to change the header.
2) Easy porting to a different compiler that uses a similar mechanism.
(gcc doesn't).

Apparently, though, MS decided that the compiler being in a different
state before and after a header is a bad thing (probably a good idea in
general) and thus made VC++8 emit a warning if a header changes the
packing without changing it back.

The solution here would be to look at the Platform SDK. Since it
contains the same technique, it should also show a way to avoid the
warning. (Probably by disabling it.) Then apply that technique to the
Boost ABI headers.

Sebastian Redl


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk