Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / CodeWarrior / April 2006



Tip: Looking for answers? Try searching our database.

struct size difference from cw to xcode

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
patate - 28 Apr 2006 15:42 GMT
Hello

I'm having a little problem, but i can't solve it :(

i have a struct that is 238120 bytes on codewarrior and it is 236708 bytes
under xcode.

( the problem being that i load binary data directly in it )

I have replaced all the bool by 'char'  , but i think there's more to it (
probably alignement or something )

Anybody has an idea of how to solve that ?

thank you
pat.
Gregory Weston - 28 Apr 2006 22:46 GMT
> Hello
>
> I'm having a little problem, but i can't solve it :(
>
> i have a struct that is 238120 bytes on codewarrior and it is 236708 bytes
> under xcode.

You have a 200k struct? Wow.

The problem is that by default there's no guarantee how any given
compiler is going to align/pack the fields of a struct. There's
typically a way to force it, though, for occasions just such as yours.

Searching for "alignment" in the full-text search mode of XCode's help I
see an entry for structure packing options mabye 10 entries down. In a
nutshell, it says you can force a specific alignment during compilation
with

#pragma pack(n) - simply sets the new alignment.

and reset to the default with

#pragma pack().

This documentation also notes a compiler switch:

-fpack-struct[=n]

"Without a value specified, pack all structure members together without
holes. When a value is specified (which must be a small power of two),
pack structure members according to this value, representing the maximum
alignment (that is, objects with default alignment requirements larger
than this will be output potentially unaligned at the next fitting
location."

I think I'd recommend the #pragma route for your needs.

Signature

"Congurutulation!!!" - The subject line on some spam I received recently.
I have no idea what it means, but it's such a cool "word" (by which I mean
pronouncable sequence of letters) regardless.

Greg - 30 Apr 2006 03:25 GMT
I would agree. A 200K struct is impressive! ;) Just in case, I would
also suggest that a portable way (after you find the proper #pragma's
as Greg suggests) is to add your own padding to the struct. Such as

unsigned char pad_1; /* unused */
unsigned short pad_2; /* unused */

This will insulate you from any potential compiler changes in the
future.

-Greg
patate - 30 Apr 2006 08:22 GMT
> unsigned char pad_1; /* unused */
> unsigned short pad_2; /* unused */
>
> This will insulate you from any potential compiler changes in the
> future.

Yes 200k is impressive :)

Thanks a lot for the alignement problem, it's exactly my problem, xcode 2.2
aligns  on 4, and codewarrior is set to 8. ( the problem being that all my
binary data has been created with an alignment of 8 )

the #pragma pack( 8 )  seemed to have no effect on xcode though :(

pat.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.