473,387 Members | 1,745 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.

Structure padding warnings when porting to 64 bit

Hi,

I am trying to port a 32 bit Unix application to 64 bit Windows. While
compiling on Windows I am getting a number of warnings related to
structure padding.
More specifically "warning C4820: 'seqargs' : '4' bytes padding added
after data member 'stop_codon_pos'"

Assuming that there is no pointer arithmetic being done on these
structures, is it ok to safely ignore this warning?

Abhishek

May 21 '07 #1
3 5133
On 21 Maj, 08:13, abhivg <abhi...@gmail.comwrote:
Hi,

I am trying to port a 32 bit Unix application to 64 bit Windows. While
compiling on Windows I am getting a number of warnings related to
structure padding.
More specifically "warning C4820: 'seqargs' : '4' bytes padding added
after data member 'stop_codon_pos'"

Assuming that there is no pointer arithmetic being done on these
structures, is it ok to safely ignore this warning?
This is probably better answered in a groups dedicated to your
compiler/platform, see the FAQ for suggestions:
http://www.parashift.com/c++-faq-lit...t.html#faq-5.9

As to your question, it's hard to tell, pointer arithmetic on the
structs themselves will probably be fine, since the compiler knows how
large the struct is. The problems that might arise is if an offset
from the address of the struct is used to access a member. Notice that
this error message would not appear if there weren't some statements
about the alignment of the struct or members thereof and I'll have to
assume that there's some reason for that (though it does not have to
be a good one).

You might want to read the documentation about the warning:
http://msdn2.microsoft.com/en-us/lib...th(vs.80).aspx

--
Erik Wikström

May 21 '07 #2
On May 21, 12:18 pm, Erik Wikström <eri...@student.chalmers.sewrote:
On 21 Maj, 08:13, abhivg <abhi...@gmail.comwrote:
Hi,
I am trying to port a 32 bit Unix application to 64 bit Windows. While
compiling on Windows I am getting a number of warnings related to
structure padding.
More specifically "warning C4820: 'seqargs' : '4' bytes padding added
after data member 'stop_codon_pos'"
Assuming that there is no pointer arithmetic being done on these
structures, is it ok to safely ignore this warning?

This is probably better answered in a groups dedicated to your
compiler/platform, see the FAQ for suggestions:http://www.parashift.com/c++-faq-lit...t.html#faq-5.9

As to your question, it's hard to tell, pointer arithmetic on the
structs themselves will probably be fine, since the compiler knows how
large the struct is. The problems that might arise is if an offset
from the address of the struct is used to access a member. Notice that
this error message would not appear if there weren't some statements
about the alignment of the struct or members thereof and I'll have to
assume that there's some reason for that (though it does not have to
be a good one).

You might want to read the documentation about the warning:http://msdn2.microsoft.com/en-us/lib...th(vs.80).aspx

--
Erik Wikström
Thanks for replying Erik,

By pointer arithmetic, I meant addition of pointers with offsets
(magic numbers). So besides use of pointers and hardcoded offsets, is
there any area where padding might be a problem?
>From what I understood, structure padding is done by the compiler
mainly to speed up memory access.

Sorry about posting my question in the wrong group. Will remember that
from now on.

regards,
Abhishek

May 21 '07 #3
On 21 Maj, 10:31, abhivg <abhi...@gmail.comwrote:
On May 21, 12:18 pm, Erik Wikström <eri...@student.chalmers.sewrote:
On 21 Maj, 08:13, abhivg <abhi...@gmail.comwrote:
Hi,
I am trying to port a 32 bit Unix application to 64 bit Windows. While
compiling on Windows I am getting a number of warnings related to
structure padding.
More specifically "warning C4820: 'seqargs' : '4' bytes padding added
after data member 'stop_codon_pos'"
Assuming that there is no pointer arithmetic being done on these
structures, is it ok to safely ignore this warning?
This is probably better answered in a groups dedicated to your
compiler/platform, see the FAQ for suggestions:http://www.parashift.com/c++-faq-lit...t.html#faq-5.9
As to your question, it's hard to tell, pointer arithmetic on the
structs themselves will probably be fine, since the compiler knows how
large the struct is. The problems that might arise is if an offset
from the address of the struct is used to access a member. Notice that
this error message would not appear if there weren't some statements
about the alignment of the struct or members thereof and I'll have to
assume that there's some reason for that (though it does not have to
be a good one).
You might want to read the documentation about the warning:http://msdn2..microsoft.com/en-us/li...th(vs.80).aspx

Thanks for replying Erik,

By pointer arithmetic, I meant addition of pointers with offsets
(magic numbers). So besides use of pointers and hardcoded offsets,
is there any area where padding might be a problem?
As long as all accesses to the struct and it's members are through
"conventional" means there should be no problem. But as I said, the
warning seems to indicate that someone have specified a specific
alignment requirement on the struct or its members, which seems to
indicate that there's some "unconventional" accesses somewhere.
From what I understood, structure padding is done by the compiler
mainly to speed up memory access.
Yes, but the padding performed by the compiler will not generate
warnings*, that only happens if the programmer have specified some
special alignments requirements on the members/struct (which will
probably slow down memory access since the layout then does not become
the one the compiler would have chosen).

* As an example consider this:
struct Foo {
char a;
int b;
};

On most modern computers there will be three bytes padding after the
char so that the int starts on a 4-byte boundary.

--
Erik Wikström

May 21 '07 #4

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

Similar topics

13
by: Amarendra | last post by:
Folks, This structure padding issue is bothering me now, could not locate a satisfactory answer on clc, so here it goes... I have a structure, given below: typedef struct { int flag; char...
2
by: Sachin | last post by:
typdef struct { int i; char ch; }str; str str_var; char x, y; main() { //do nothing
15
by: damian birchler | last post by:
Hi I'm wondering of what type a structure is. Of course, it is a _structure_, but an array isn't an _array_ either. So of what type is a structure? I'd say a pointer, am I right?
1
by: pmm | last post by:
hi I am repeating my post here plz excuse i am trying out a UDP packet transfer between a windows machine and a linux I created a structure on both sides (ie on linux and on windows) and I sent...
28
by: kyle york | last post by:
Greetings, Why does the C standard require the members of a structure not be re-ordered (6.2.5.20)? Padding is allowed, and platform dependent, which means one cannot rely on the exact layout...
4
by: junky_fellow | last post by:
Can somebody please tell me about the structure alignment rules ? What I found was that on my system (cygwin running on PC, size of int=4 sizeof long=4, size of long long = 8) the cygwin compiler...
5
by: lovecreatesbea... | last post by:
Does the expression *(int *)&s1 below inside the printf() statement guarantee to refer to the first member of the structure variable s1? I've tried the code and it seems that it works that way. The...
24
by: karthikbalaguru | last post by:
Hi, I find that the structure padding is not being taken into account while using 'new' operator. Is there a way to enable it ? struct Dataunit { char dataid; int keyid;
12
by: Kislay | last post by:
case 1 : struct s { char c1; // 8 double d; // 8 int i1; // 4 char c2; // 4 int i2; // 4 };
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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
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,...
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...

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.