• 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: Control initialised data layout?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Control initialised data layout?


  • Subject: Re: Control initialised data layout?
  • From: Fritz Anderson <email@hidden>
  • Date: Mon, 30 Jul 2007 14:26:37 -0500

On 30 Jul 2007, at 12:07 PM, Greg Guerin wrote:

Martin Crane wrote:

static unsigned char gBuffer1[8] = { 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h'};
unsigned char gBuffer2[8] = { 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a'};

How about defining it as a struct, whose layout you can control. A struct
is what should have been done in the first place.


typedef struct gbuff
 { unsigned char buf1[8]; unsigned char buf2[8]; }
 gbuff;

static gbuff gBuffer12 = {
 { 'a', 'b', 'c', 'd', 'e', 'f',  'g', 'h'},
 { 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a'}  };

I seem to remember that C does not in general guarantee that struct members will be contiguous. This solution would happen to work well in the case of eight-char arrays, but what if the first array is of a size that doesn't meet an alignment boundary?


I suppose one could do

typedef struct gbuff __attribute__((__packed__))
 { unsigned char buf1[8]; unsigned char buf2[8]; }
 gbuff;

The problem of __attribute__ being a gcc extension could be taken care of by #define-ing PACKED_STRUCT as __attribute__((__packed__)) for gcc builds, and as empty for others.

	— F

_______________________________________________
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: 
 >Re: Control initialised data layout? (From: Greg Guerin <email@hidden>)

  • Prev by Date: Disable Localization?
  • Next by Date: Setting SVN repository
  • Previous by thread: Re: Control initialised data layout?
  • Next by thread: Re: Control initialised data layout?
  • Index(es):
    • Date
    • Thread