> 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.