Structure padding warnings when porting to 64 bit

A

abhivg

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
 
?

=?iso-8859-1?q?Erik_Wikstr=F6m?=

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-lite/how-to-post.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/library/t7khkyth(vs.80).aspx
 
A

abhivg

This is probably better answered in a groups dedicated to your
compiler/platform, see the FAQ for suggestions:http://www.parashift.com/c++-faq-lite/how-to-post.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/library/t7khkyth(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?
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
 
?

=?iso-8859-1?q?Erik_Wikstr=F6m?=

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top