473,387 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 3877

--------------------
From: "Hendrik Schober" <Sp******@gmx.de>
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.public.dotnet.languages.vc
NNTP-Posting-Host: 212.99.150.86
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vc:27852
X-Tomcat-NG: microsoft.public.dotnet.languages.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.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

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.microsoft.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.de> 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_TestEntries[] = {
{ 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.de> wrote in message
news:ej**************@TK2MSFTNGP09.phx.gbl...
"Hendrik Schober" <Sp******@gmx.de> 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_TestEntries[] = {
{ 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
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...
12
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...
18
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...
8
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...
1
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...
1
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
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...
4
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
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.