473,657 Members | 2,489 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Packing MESS

Hello,
what I'm saying here is about VS 2005 WITHOUT service pack.

I have two DLL projects, with EXACTLY the same project preferences and
settings. Both have alignment set to "default", it should be 8.

Surpise number one:
In project B I include a file of project A in this way
#include <FILE_FROM_A. h>

it generates classes inside the include with an alignment of "1", but
only in project B . I've checked everything, I don't change it with
#pragma pack anywhere.

The code (in project B)
#pragma pack(show)
#include <FILE_FROM_A. h>

displays a warning similar to "Pragma pack = 1"
even if I set it to 8 explicitly from the project settings.

Surprise number two:
#pragma pack(8)
#include <FILE_FROM_A. h>

if I insert into FILE_FROM_A.h the line
#pragma pack(show)

When I compile project A it shows me 8. Else it shows me 1 anyway !!!

Surprise number three:
When I finally get it to work by explicitly setting packing into each
file with #pragma pack, it works (the classes have the same aligment),
but the class is 4 bytes larger in project A that in project B. I
repeat: SAME preprocessor definitions, SAME project settings.

I spent one hour realizing that was an aligment problem :)
Someone had similar issues?

QbProg

Feb 14 '07 #1
1 1647
QbProg wrote:
#pragma pack(8)
#include <FILE_FROM_A. h>

if I insert into FILE_FROM_A.h the line
#pragma pack(show)

When I compile project A it shows me 8. Else it shows me 1 anyway !!!
Then one of your include files is clearly changing the alignment and not
resetting it back. Everyone who explicitly modifies packing should use
the following pattern:

#pragma pack(push,N)
// modify and save
struct C
{
....
};
#pragma pack(pop)
//restore!!!

Mayb it's a 3rd party header file that causes the problem. You have to
find which one it is, and modify it to use the push and pop concept.
Surprise number three:
When I finally get it to work by explicitly setting packing into each
file with #pragma pack, it works (the classes have the same aligment),
but the class is 4 bytes larger in project A that in project B. I
repeat: SAME preprocessor definitions, SAME project settings.
Are you using VS2005 exclusively, or are you mixing compilers?

You must be overlooking one #pragma push or one #define. If two classes
don't have the same size, that's due to something being different.

It's not enough to ensure that alignment for your class is correct, you
also have to make sure that the alignment of all members are matching too:

Example:

#pragma pack(push,1)
struct A
{
char c;
int i;
};
#pragma pack(pop)

#pragma pack(push,8)
struct B
{
A a;
};
#pragma pack(pop)

Despite the alignment for "B" is explicitly set to 8, its member "a" is
still aligned to 1. "A" may be coming from somewhere else, which you
might have overlooked.

Or you have conditions in the header file:

struct B
{
#ifndef NDEBUG
int only_for_debugg ing;
#endif
...
};

It's easy to overlook such a thing. This happened to me, when my DLL was
in release mode and the executable in debug, and the header file
contained an NDEBUG conditional.

Maybe you could use the offsetof macro to check which exact member
causes the mismatch.

Tom
Feb 14 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1667
by: ZaGras | last post by:
after i pack my vb program using package and deployment wizard, i try to install the program on other computer instead of my computer and run the program. when i click to add a new record to the Microsoft Access database, the following error message was prompted out: item cannot be found in the collection corresponding to the requested name or ordinal. Error number: 3265 when i click on one button which will query the Microsoft Access...
0
1255
by: nobull | last post by:
Google won't let me post this as a follow-up but lynch@agere.com (lynto) wrote in message news:<503469eb.0407271148.7ee4b0ca@posting.google.com>... > Does anyone have an algorithm for packing registers? Algorithms are language independant so this question is off topic in comp.lang. It appears that you are taking about the famous "packing problem" which is, I believe, fairly trivially, mathematically equivalent to the even more...
2
1929
by: gbb0330 | last post by:
Hi all I need some advice. the daily packing number will be used to match a box with its label. the guys in the warehouse will get a list of items to pack. they will find the item - put it in a box and click a button at this point the daily packing packing number will be genrated. the packing guy will write it on the box.
1
1825
by: gbb0330 | last post by:
hi guys -the code (all capital letters) generates daily packing number, it is in the on click event of a command button that moves to the next record. dpkn is unbound control - i use it to display the last daily packing number genrated, so when the user moves to a new control they will know what the last daily packing number was. PdailyPackingNumber is bound and is 0 until the user clicks the button.
2
5950
by: FMorales | last post by:
Hello all, quick hopefully easy question. Here goes. I've started on the Art Of Assembly tutorial(s) (http://webster.cs.ucr.edu/Page_asm/0_ArtOfAsm.html) and got to the sample projects and kinda got stuck. I'm needing to use a language of my choosing (which i easily chose C) to do this project where it wants me to pack data into a 16 bit variable. Now i am familiar with C to a pretty decent extent, just not bit manipulation. So what...
18
2033
by: Edward Diener | last post by:
Is the packing alignment of __nogc classes stored as part of the assembly ? I think it must as the compiler, when referencing the assembly, could not know how the original data is packed otherwise. Yet, in my understanding, attributes are only __gc and __value class specific and do not apply to __nogc classes. Is this correct ? If so, how is the packing alignment of __nogc classes stored ?
1
3171
by: Gajendra | last post by:
How does the byte packing and the byte alignment work in VC++ compiler? What is the effect of #pragma pack(n) on the alignment and byte packing for example while using the structur struc double a char b char c } in a 8 byte packing the sizeof structure is 16. Could anyone explain.
2
1699
by: Dr John Stockton | last post by:
Page <URL:http://www.merlyn.demon.co.uk/js-quick.htm> now contains code to pack text into multiple paragraphs of given right margin (the nominal range is from 1 to nearly Infinity). function Pak(F) { var S = F.Code.value, L = +F.Len.value, J, Re S = S.replace(/(\r?\n){2,}/g, "\u0000").replace(/(\r?\n)/g, " ") S = S.replace(/\s+/g, " ").split("\u0000") if (L<1) L = F.Len.value = 1 Re = new RegExp("(.{1," + L + "}) ", "g")
9
5859
by: fraz | last post by:
Does anyone have code to solve a 3-d bin packing problem in php? I am trying to solve the issue of packing various sized rectangular shaped objects into boxes of three different sizes so as to use as few packing peanuts as possible (to some reasonable approximation) to fill the gaps. I have found some c code and plenty of discussions on the subject, but I was thinking that someone out there has to have done this in php already.
0
8823
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8726
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7320
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1944
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1604
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.