Account Options

  1. Sign in
Google Groups Home
« Groups Home
Message from discussion Structure alignement problem
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Doug Harrison [MVP]  
View profile  
 More options Mar 15 2005, 10:31 am
Newsgroups: microsoft.public.vc.mfc
From: "Doug Harrison [MVP]" <d...@mvps.org>
Date: Tue, 15 Mar 2005 09:31:00 -0600
Subject: Re: Structure alignement problem

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.

--
Doug Harrison
Microsoft MVP - Visual C++


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.