• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: alignment issue - Codewarrior vs XCode
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: alignment issue - Codewarrior vs XCode


  • Subject: Re: alignment issue - Codewarrior vs XCode
  • From: Brian Bergstrand <email@hidden>
  • Date: Tue, 12 Jul 2005 11:41:13 -0500

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


On Jul 12, 2005, at 11:04 AM, Alan Dail wrote:

The first part of the file is a header that is created by simply block writing a struct to disk. Not the best approach for sure, but that's what I have to work with at this point. The struct has a bunch of shorts/long/bool/etc. The problem I'm running into is the struct is a different length in XCode as it is in codewarror. And setting pragma align statements to adjust it not only isn't helping, but is actually giving me different results on the different compilers.

1) Whenever you write any binary data to disk/network you should always pack it to avoid just this problem. Different compilers may pad (align) structures differently.


#pragma pack(1)

struct my_disk_struct {
 ...
};

#pragma pack()

2) Different compilers may also have different type sizes:

For instance, bool is 4 bytes on gcc, but for most other compiler's it's 1 byte, and the 64 bit ABI that most follow defines a "long" type as 8 bytes, while "long" is 4 bytes in a 32 bit ABI.

Your best bet is to use the int32_t and friends typedef's -- that way you know the size being written and read from disk/network will match.

HTH.

Brian Bergstrand
<http://www.bergstrand.org/brian/>   PGP Key ID: 0xB6C7B6A2

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Darwin)

iD8DBQFC0/KuedHYW7bHtqIRAsoBAKDJm3R+qMc4ob+Wt1KBsOwX0Ws5RgCeLx3E
08khvrcVmOOyY9uXxMouwf4=
=RIDx
-----END PGP SIGNATURE-----
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Apple system icons: guidelines for use in Cocoa applications? (From: Kevin Walzer <email@hidden>)
 >alignment issue - Codewarrior vs XCode (From: Alan Dail <email@hidden>)

  • Prev by Date: Re: alignment issue - Codewarrior vs XCode
  • Next by Date: Re: alignment issue - Codewarrior vs XCode
  • Previous by thread: Re: alignment issue - Codewarrior vs XCode
  • Next by thread: Re: alignment issue - Codewarrior vs XCode
  • Index(es):
    • Date
    • Thread