On Tue, 15 Mar 2005 14:56:21 +0100, Arsalan Ahmad wrote: > Hi all,
> In my mfc application, in compiler settings i have changed struct member > alignment to 1 byte and this is working in debug mode. But when i tried to > do this in release mode of my application then i got following warning in > compilation of almost all the cpp files in release mode:
> D:\arsalan\MyApplication\StdAfx.cpp(5) : warning C4653: compiler option > 'structure packing (/Zp)' inconsistent with precompiled header; current > command-line option ignored
> Compiling...
> And thus my application in release mode is not working because i have some > structures which must be 1 byte aligned for their members.
> Could you please tell me how can I make this work in release mode.
Instead of using /Zp, you should use #pragma pack along with #pragma push/pop to control the packing of specific structs. Here's why.
You should not fool around with the default packing. While the CRT headers and most of the Windows headers are diligent about setting the packing they expect and restoring the original packing, this is far from universal. You're begging for trouble if you use /Zp on code you didn't write yourself, such as libraries you may be using, and even some of the Windows headers, e.g. <wincon.h>, which last I checked (Jan 2004), has a problem with its KEY_EVENT_RECORD struct under non-default packing. You can easily cause your code to observe different class layouts than the libraries you're using, which will really mess you up. On a non-Intel CPU, straying from the default would almost certainly result in a horrendously slow application or outright crashing due to misaligned data access. That's true for cases in which changing the default packing *works*, in the sense that everyone agrees on class layouts; on Intel CPUs, you would merely observe slightly slower data access.