473,748 Members | 2,551 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems with "default" alignment beeing different

Hi,

we just run into the problem, that "default" alignment
in the project properies dialog seem to be different.
We have a project that's a DLL, which is linked with
a couple of LIBs. All are with the same solution. All
had "Default" set in the "Struct Member Alignment"
entry.
After some assembler debugging we found out that a
struct member that is a member function pointer in
one of the LIBs was expected at a different position
than in the DLL.
Setting the alignment to /Zp4 in all projects made
the problem disappear.

I don't understand that.
What's the "Default" setting defaulting to? And why
is that different in projects of the same solution?

Schobi

--
Sp******@gmx.de is never read
I'm Schobi at suespammers org

"And why should I know better by now/When I'm old enough not to?"
Beth Orton
Nov 16 '05 #1
5 3913

--------------------
From: "Hendrik Schober" <Sp******@gmx.d e>
Subject: Problems with "default" alignment beeing different
Date: Wed, 3 Sep 2003 12:35:56 +0200
Lines: 29
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <Os************ **@TK2MSFTNGP10 .phx.gbl>
Newsgroups: microsoft.publi c.dotnet.langua ges.vc
NNTP-Posting-Host: 212.99.150.86
Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP10.phx.g bl
Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.vc:27852
X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vc

Hi,

we just run into the problem, that "default" alignment
in the project properies dialog seem to be different.
We have a project that's a DLL, which is linked with
a couple of LIBs. All are with the same solution. All
had "Default" set in the "Struct Member Alignment"
entry.
After some assembler debugging we found out that a
struct member that is a member function pointer in
one of the LIBs was expected at a different position
than in the DLL.
Setting the alignment to /Zp4 in all projects made
the problem disappear.

I don't understand that.
What's the "Default" setting defaulting to? And why
is that different in projects of the same solution?

Schobi

--
Sp******@gmx.d e is never read
I'm Schobi at suespammers org

"And why should I know better by now/When I'm old enough not to?"
Beth Orton

Hi Schobi,

You can inspect the log file to see if any other alignment was being
specified. Once a build is done, a link is provided to an HTML version of
the log file in the Output window. Note that the value of the default
alignment is different for different platforms. On x86, it's /Zp4; on IA64
it's /Zp8, etc.

However, the fact that a pointer-to-member was involved causes me to think
of one other case that can cause different packing of structures containing
pointers to members. Consider this:

// File 1.cpp:

struct C; // no definition provided <------------- NOTE THIS

typedef void (C::*PTM)();

struct X {
PTM ptm1;
PTM ptm2;
};

// File 2.cpp

struct C { /*...*/ }; /* definition provided */

typedef void (C::*PTM)();

struct X {
PTM ptm1;
PTM ptm2;
};
You'll find that the size of struct X in the two translation units is
different because in 1.cpp, since the inheritance characteristics
(multiple, virtual, none) of struct C are unknown, VC presumes the most
general kind of pointer to member and allocates more than 4 bytes to it.
This can cause the offsets of ptm2 to be different in the two translation
units. It's worth checking that in all translation units were a pointer to
member of class C is defined, the definition of class C is available. If C
is an instantiatable class (doesn't contain any pure virtuals or private
default constructors), a simple definition of a global (static) variable
should do the job.

--
Tanveer Gani, Microsoft Visual C++ Team
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
Nov 16 '05 #2
"Tanveer Gani [MSFT]" <tg***@online.m icrosoft.com> wrote:
[...]
Hi Schobi,

You can inspect the log file to see if any other alignment was being
specified. Once a build is done, a link is provided to an HTML version of
the log file in the Output window. Note that the value of the default
alignment is different for different platforms. On x86, it's /Zp4; on IA64
it's /Zp8, etc.
I know. There wasn't any difference between the
LIB and DLL project that seemed important.
However, putting the LIB's sources into the DLL
cured the problem.
However, the fact that a pointer-to-member was involved causes me to think
of one other case that can cause different packing of structures containing
pointers to members. Consider this:

[...]
That's interesting. I didn't know that.
However, since simply putting the sources into
the same project cured the problem, it seems
unlikely that this was the cause.

I'm afraid the guy who run into this feels he
wasted too much time on this issue and won't
put anymore into this now that he found some
workaround. I hope that won't bite us in the
end, but I can't find any time either.

Thanks for looking into this.
Tanveer Gani, Microsoft Visual C++ Team


Schobi

--
Sp******@gmx.de is never read
I'm Schobi at suespammers org

"And why should I know better by now/When I'm old enough not to?"
Beth Orton
Nov 16 '05 #3
"Hendrik Schober" <Sp******@gmx.d e> wrote:
Hi,

we just run into the problem, that "default" alignment
in the project properies dialog seem to be different.
We have a project that's a DLL, which is linked with
a couple of LIBs. All are with the same solution. All
had "Default" set in the "Struct Member Alignment"
entry.
After some assembler debugging we found out that a
struct member that is a member function pointer in
one of the LIBs was expected at a different position
than in the DLL.
Setting the alignment to /Zp4 in all projects made
the problem disappear.
[...]


Unfortunately, it didn't make it disappear,
it just changed the problem, so that it arose
somewhere else.
We have been further investigating this. So
here's an update.

We compile a bunch of code into a LIB file and
link this into our executable. (The code isn't
ours.)
It seems as if pointers to member functions are
aligned differently in the LIB than in the EXE,
even though all compiler settings are the same.
(We checked this several times.)

Assuming I want to use pointers to a struct's
members within a table like this

const TTestStruct c::sm_TestEntri es[] = {
{ 1, 2, 3, &c::f1, &var},
{ 4, 5, 6, &c::f1, &var},
{ 0, 0, 0, 0, 0}
};

using default alignment I end up with this
memory layout (all in 4byte words):

0001 0002 0003 0000 &f1 0000 0000 0000 &var
0004 0005 0006 0000 &f1 0000 0000 0000 &var
0000 0000 0000 0000 0000 0000 0000 0000 0000

Using 4byte alignment (/Zp4) I get this:

0001 0002 0003 &f1 0000 0000 0000 &var
0004 0005 0006 &f1 0000 0000 0000 &var
0000 0000 0000 0000 0000 0000 0000 0000

So far, so good. However, in the LIB I get
this:

0001 0002 0003 &f1 &var
0004 0005 0006 &f1 &var
0000 0000 0000 0000 0000

no matter what the alignment is set to.
I know that smells as if the alignment is set
explicitely somewhere within the code. However,
there's a few things against this:
1. Despite intensive search by three people
(including me), we didn't find any.
2. It used to work with VC6.
3. A '#pragma pack(show)' at the appropriate
places showed identical values for LIB and
EXE.
While I would argue about #1, probably even #2,
#3 seems to indicate that there isn't any packing
manipulation done.
We haven't been able to come up with a repro case
and the code in question is rather big. So we
merely are still blindly stumbling around,
searching for something to start with.
Any ideas out there about that?

Schobi

--
Sp******@gmx.de is never read
I'm Schobi at suespammers org

"And why should I know better by now/When I'm old enough not to?"
Beth Orton
Nov 16 '05 #4
Try and compile everything explicitly with /vmg /vmv (or /vmg /vmm if you
use MI, but not virtual inheritance). Look at the help for both compiler
options for more background.

Ronald Laeremans
Visual C++ team

"Hendrik Schober" <Sp******@gmx.d e> wrote in message
news:ej******** ******@TK2MSFTN GP09.phx.gbl...
"Hendrik Schober" <Sp******@gmx.d e> wrote:
Hi,

we just run into the problem, that "default" alignment
in the project properies dialog seem to be different.
We have a project that's a DLL, which is linked with
a couple of LIBs. All are with the same solution. All
had "Default" set in the "Struct Member Alignment"
entry.
After some assembler debugging we found out that a
struct member that is a member function pointer in
one of the LIBs was expected at a different position
than in the DLL.
Setting the alignment to /Zp4 in all projects made
the problem disappear.
[...]


Unfortunately, it didn't make it disappear,
it just changed the problem, so that it arose
somewhere else.
We have been further investigating this. So
here's an update.

We compile a bunch of code into a LIB file and
link this into our executable. (The code isn't
ours.)
It seems as if pointers to member functions are
aligned differently in the LIB than in the EXE,
even though all compiler settings are the same.
(We checked this several times.)

Assuming I want to use pointers to a struct's
members within a table like this

const TTestStruct c::sm_TestEntri es[] = {
{ 1, 2, 3, &c::f1, &var},
{ 4, 5, 6, &c::f1, &var},
{ 0, 0, 0, 0, 0}
};

using default alignment I end up with this
memory layout (all in 4byte words):

0001 0002 0003 0000 &f1 0000 0000 0000 &var
0004 0005 0006 0000 &f1 0000 0000 0000 &var
0000 0000 0000 0000 0000 0000 0000 0000 0000

Using 4byte alignment (/Zp4) I get this:

0001 0002 0003 &f1 0000 0000 0000 &var
0004 0005 0006 &f1 0000 0000 0000 &var
0000 0000 0000 0000 0000 0000 0000 0000

So far, so good. However, in the LIB I get
this:

0001 0002 0003 &f1 &var
0004 0005 0006 &f1 &var
0000 0000 0000 0000 0000

no matter what the alignment is set to.
I know that smells as if the alignment is set
explicitely somewhere within the code. However,
there's a few things against this:
1. Despite intensive search by three people
(including me), we didn't find any.
2. It used to work with VC6.
3. A '#pragma pack(show)' at the appropriate
places showed identical values for LIB and
EXE.
While I would argue about #1, probably even #2,
#3 seems to indicate that there isn't any packing
manipulation done.
We haven't been able to come up with a repro case
and the code in question is rather big. So we
merely are still blindly stumbling around,
searching for something to start with.
Any ideas out there about that?

Schobi

--
Sp******@gmx.de is never read
I'm Schobi at suespammers org

"And why should I know better by now/When I'm old enough not to?"
Beth Orton

Nov 16 '05 #5
"Ronald Laeremans [MSFT]" <ro*****@online .microsoft.com> wrote:
Try and compile everything explicitly with /vmg /vmv (or /vmg /vmm if you
use MI, but not virtual inheritance). Look at the help for both compiler
options for more background.
Thanks for looking at this, Ronald.

In the test project we have to play with this
(it doesn't reproduce the problenm, though), we
see how this affects the member pointer layout.
It doesn't seem to solve the problem in the real
project, though. (AFAIK there isn't any pointer
into a forward declared class' member involved.)

However, this seems to hint at the problem. As
the problem was explained to me, it seems that
there is a class hierarchy in the LIB that doesn't
have MI. There's an array defined, which contains
pointers to members of classes from that hierarchy.
In the executable, there's further inheritance
from those classes, this time involving MI.
Right now we try to remove that MI (it seems it
isn't really necessary) to see if that helps.
Ronald Laeremans
Visual C++ team
[...]


Schobi

--
Sp******@gmx.de is never read
I'm Schobi at suespammers org

"And why should I know better by now/When I'm old enough not to?"
Beth Orton
Nov 16 '05 #6

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

Similar topics

8
5742
by: whtevr | last post by:
Consider this HTML on an ASP page called default.asp in a virtual directory: <FORM name="Flogin" id="Flogin" action="" method=post> </FORM> Do I HAVE to put the literal "default.asp" into the action attrib to get this form to post back to the "default.asp" page in that directory?
12
4951
by: Stefano | last post by:
Hi all, what is the correct use of the "default" attribute in XML Schema? For example: <xs:element name="myProperty" type="xs:string" default="myDefaultValue"/> What can I do with it? What is the meaning of < ....default="myDefaultValue" /> ?
18
2253
by: Clark Nu | last post by:
It seems that when I define a fuction,I can set a default value to some of the peremeters.When I call the fuction without some of them,the fuction will use the default value automaticlly then continue to work.But I'v fogot how to use,even I'v fogot whether I can use it in C# or not. Help me.
8
3512
by: Bern McCarty | last post by:
Is it at all possible to leverage mixed-mode assemblies from AppDomains other than the default AppDomain? Is there any means at all of doing this? Mixed-mode is incredibly convenient, but if I cannot load/unload/reload extensions into my large and slow-to-load application during development without restarting the process then the disadvantages may outweigh the advantages. I've got a mixed-mode program in which I create a new AppDomain...
1
2005
by: welles.lo | last post by:
Hi all, I found that the default "can grow" in Crystal Reports 10 is different from the one in Crystal Report 9. In version 9, when "can grow" is disable, the words in the field are chopped off and doesn't not warp around to the next line. In version 10, when "can grow" is disable ,the text would overlap the field next to it if the text is too long, to make it field behave the
1
1702
by: test | last post by:
Using a DetailsView to update data in SQL 2005, How do I change the default "Update" hyperlink to a more user friendly button? Thanks
3
2558
by: kjworm | last post by:
Greetings, I have a report displayed on a screen that anyone in the office can look at. The data on this report will change from time to time. This report has different colors displayed depending on the data. Since I'm using Access '97, I can't do this on a form. What I am doing is "refreshing" this report every 60 seconds. Since Access '97 can't use the timer interval for reports, I have a form that is closing and then reopening my...
4
1426
by: Ed | last post by:
Hi, guys, Here is a simple template class definition: template <typename T = int> class Point { public: T X; T Y; T Z; };
2
1600
by: LinNan | last post by:
When C source code is compiled into an object file (.o), the functions are put into the .text section. Is it possible that I put all functions to a renamed text section whose name may be ".text.app". When linking several .o files into an executable, I need to put the code of .o files into different positions(in MCU). If I can rename the text section of object files, I can set different section start addresses for each section.
0
8996
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9386
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
9333
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
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8255
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...
0
4608
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...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2217
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.