Board index » cppbuilder » Data alignment problem in C++2007

Data alignment problem in C++2007


2007-09-05 10:57:17 PM
cppbuilder18
I think I have encountered a problem with data alignment in C++007 with
update 2.
If the following code example is run, with the project data alignment set
option set to 'Double Word', the size of foo (=24) doesn't equal foo2 (=16).
Under BDS2006, the size of foo and foo2 are the same (=16)
#pragma argsused
int main(int argc, char* argv[])
{
struct foo
{
char c;
double dval;
int ival;
};
#pragma pack(push, 4)
struct foo2
{
char c;
double dval;
int ival;
};
#pragma pack(pop)
cout << "size of foo:" << sizeof( foo ) << endl;
cout << "size of foo2:" << sizeof( foo2 ) << endl;
getch();
return 0;
}
Simon
 
 

Re:Data alignment problem in C++2007

"Simon Hooper" < XXXX@XXXXX.COM >writes:
Quote
I think I have encountered a problem with data alignment in C++007 with
update 2.

If the following code example is run, with the project data alignment set
option set to 'Double Word', the size of foo (=24) doesn't equal foo2 (=16).
Under BDS2006, the size of foo and foo2 are the same (=16)
Right. Why do you find this difference a surprise?
Quote
#pragma argsused
int main(int argc, char* argv[])
{

struct foo
{
char c;
double dval;
int ival;
};

#pragma pack(push, 4)
struct foo2
{
char c;
double dval;
int ival;
};
#pragma pack(pop)
Between your pragma pack/(push..pop) you have explicitly set the
alignment to 4, overriding the default value of 8. That takes higher
precedence than the global default value, and SHOULD cause the
alignment of foo2 to be different.
--
Chris (TeamB);
 

Re:Data alignment problem in C++2007

Ok I agree...but why if I set the the data alignment to 4byte/Word (in both
IDE) does size of foo equal 16 bytes in BDS2006 (=16) but 14 bytes in
C++2007.
Regards Simon
 

{smallsort}

Re:Data alignment problem in C++2007

"Simon Hooper" < XXXX@XXXXX.COM >writes:
Quote
Ok I agree...but why if I set the the data alignment to 4byte/Word (in both
IDE) does size of foo equal 16 bytes in BDS2006 (=16) but 14 bytes in
C++2007.
Now that *is* surprising to me. Unfortunately, to try to answer I
would have to throw completely wild guesses at you. (None of which
would be very good, I'd imagine.)
--
Chris (TeamB);
 

Re:Data alignment problem in C++2007

In article <46dec3ce$ XXXX@XXXXX.COM >,
"Simon Hooper" < XXXX@XXXXX.COM >wrote:
Quote
I think I have encountered a problem with data alignment in C++007 with
update 2.
It appear that the -a4 option isn't getting passed to the compiler.
Go ahead and log this in QC, and I'll promote it.
--
-David Dean
CodeGear C++ QA Engineer
<blogs.codegear.com/ddean/>
 

Re:Data alignment problem in C++2007

Quote
Go ahead and log this in QC, and I'll promote it.
Thanks David, reported as #51652. I hope 'promote it' means 'get it fixed
and get an update released'. Finally started using C++2007 following release
of update 2. I have to say I am very disappointed at the moment. Unable to
get release build of our project to work at the moment. More to comment upon
later.
Please also promote #50374.
Simon