• 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 in structs
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Alignment in structs


  • Subject: Re: Alignment in structs
  • From: Steve Christensen <email@hidden>
  • Date: Mon, 17 Jul 2006 12:46:48 -0700

On Jul 17, 2006, at 11:29 AM, Rush Manbert wrote:

Laurence Harris wrote:

Okay, this is weird. I took out the __attribute__((__packed__)) when I got the error. Then I put it back and was going to use your suggestion, but I don't get the error now. I wonder if there was some kind of compiler error the first time.

From what I've read, it appears that gcc would not complain if the calling argument were a const reference. It seems that read only access of packed data members is fine, but write access through a reference is not. If the calling argument is a pointer to UInt32, that will be okay with the compiler too. I don't really understand why references are restricted in this way, but I assume there's a good (if obscure) reason.

Unaligned accesses can cause a crash on some processors so gcc may just be generalizing for that case. Thus, calling


    void foo(UInt32 x);

would be fine for all cases since the compiler could generate the appropriate instructions to gather up all the pieces for x and pass a UInt32 value into foo. Calling

    void foo(UInt32& x);

would be problematic because foo doesn't know that x is potentially misaligned.

What is it that you're really trying to achieve? Do you have a billion instances of Blah, so you need to save those 2 bytes? Are you sending Blahs over the wire to a remote location using some custom protocol? Or does it just bug you that the size is padded out?

The simplest answer might be backwards compatibility. Like, say, if the structure referred to legacy preferences. Even if you plan to update the preferences to something more modern, such as a plist, you'd still want to be able to read the old preferences.


steve



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Alignment in structs
      • From: Rush Manbert <email@hidden>
References: 
 >Alignment in structs (From: Laurence Harris <email@hidden>)
 >Re: Alignment in structs (From: Rush Manbert <email@hidden>)
 >Re: Alignment in structs (From: Laurence Harris <email@hidden>)
 >Re: Alignment in structs (From: Steve Checkoway <email@hidden>)
 >Re: Alignment in structs (From: Laurence Harris <email@hidden>)
 >Re: Alignment in structs (From: Rush Manbert <email@hidden>)

  • Prev by Date: Re: Alignment in structs
  • Next by Date: Alternate name for InfoPlist.strings?
  • Previous by thread: Re: Alignment in structs
  • Next by thread: Re: Alignment in structs
  • Index(es):
    • Date
    • Thread