Re: Control initialised data layout?
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