• 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 Checkoway <email@hidden>
  • Date: Fri, 14 Jul 2006 18:41:40 -0700


On Jul 14, 2006, at 6:05 PM, Laurence Harris wrote:


On Jul 14, 2006, at 6:59 PM, Rush Manbert wrote:

Laurence Harris wrote:
What do I need to set in Xcode to get the size of this struct:
typedef struct Blah {
    UInt32        a, b, c;
    SInt16        d;
} Blah;
to be 14 instead of the 16 I'm getting currently? Thanks,

Try this:

typedef struct Blah {
    UInt32        a, b, c;
    SInt16        d;
} __attribute__((__packed__)) Blah;

When I try this, the following line:

err = Foo( x, data.a );

generates this warning:

: error: cannot bind packed field 'data.Blah::a' to 'UInt32&'

OSErr Foo ( FSVolumeRefNum inVRefNum, UInt32 &inID );

Just a guess but the packed fields do not necessarily have the natural alignment that that would be required for that type so gcc either has to do some unaligned loads or load the surrounding bytes and do some bit shifts. A reference is just like a pointer (with fewer capabilities) and wouldn't handle unaligned loads/stores. There might be a way to get gcc to emit code to check the address and handle calls to Foo with both aligned and unaligned reference parameters but I don't know how. I'd avoid packing your struct if at all possible or doing:


Blah data = { 1, 2, 3, 4 };
UInt32 a = data.a;
err = Foo( x, a );
data.a = a;

--
Steve Checkoway



Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
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: Laurence Harris <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>)

  • Prev by Date: Re: warning: enumeral mismatch
  • Next by Date: Re: Alignment in structs
  • Previous by thread: Re: Alignment in structs
  • Next by thread: Re: Alignment in structs
  • Index(es):
    • Date
    • Thread