• 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: Eric Albert <email@hidden>
  • Date: Fri, 14 Jul 2006 16:51:39 -0700

On Jul 14, 2006, at 4:41 PM, Laurence Harris wrote:

On Jul 14, 2006, at 6:57 PM, Eric Albert wrote:

On Jul 14, 2006, at 3:49 PM, 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,

#pragma pack(2)

typedef struct Blah {
	UInt32		a, b, c;
	SInt16		d;
} Blah;

#pragma pack()

Hope this helps,

Thanks. Now, would I see padding issues with this as well:

typedef struct Blah {
	SInt16		d;
	UInt32		a, b, c;
} Blah;

Depends on what you mean by padding issues. On a 32-bit system using normal 4-byte alignment, d will be at offset 0, followed by two bytes of padding, followed by a, b, and c. #pragma pack(2) will pack them all together, so a will be at offset 2, b at offset 6, and c at offset 10.


-Eric

_______________________________________________
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


References: 
 >Alignment in structs (From: Laurence Harris <email@hidden>)
 >Re: Alignment in structs (From: Eric Albert <email@hidden>)
 >Re: Alignment in structs (From: Laurence Harris <email@hidden>)

  • Prev by Date: Re: Alignment in structs
  • Next by Date: Re: Header Search Paths / Multiple Header Files with the same name
  • Previous by thread: Re: Alignment in structs
  • Next by thread: Re: Alignment in structs
  • Index(es):
    • Date
    • Thread