At 12:26 2002-10-25 -0700, you wrote:
Looking at the C++ standard, the behavior here is determined by section 12.8, "Copying class objects". The implicitly defined copy constructor has several requirements:Perhaps this is something the CodeWarrior folks might want to look into. I realize that C++ changed the symantics of structure assignment from C to be a logical assignment of the fields rather than a logical block copy (different when there are gaps due to alignment), and also that in more complex cases there is the potential of constructors and/or operators needing to be called for some of the fields. However, in the simple/common/important case where the struct is fully packed and has no members needing special handling, you should get a straight memory copy.
1) perform a memberwise copy of its subobjects
2) order of copying is the same as the of initiation of its base classes and members in a user-defined constructor
This is what guides the current CW implementation, and this why the copy behavior differs from C to C++.
The lack of this optimization was a known issue with the C++ front end, and I brought this up with the C++ technical lead at Metrowerks back in April, and this optimization has been implemented in the 3.0 FE, but is not on by default. To enable it, you need to add
#pragma block_assign on
to your source files or header file. It is not enabled by default because it can cause missed optimization opportunities for some code because the compiler is no longer able to split a single struct into multiple scalar variables for independent assignment to registers or the stack.
I just verified that using this pragma produced better assignment generation code for the example you provided.
The 3.0 front-end will ship as part of the 68K and ARM compilers in the CodeWarrior Developer Studio for Palm OS, Version 9 product in December.
--
Ben Combee <[EMAIL PROTECTED]>
CodeWarrior for Palm OS technical lead
Palm OS programming help @ www.palmoswerks.com
--
For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
