Re: Control initialised data layout?
Re: Control initialised data layout?
- Subject: Re: Control initialised data layout?
- From: Greg Guerin <email@hidden>
- Date: Mon, 30 Jul 2007 13:11:22 -0700
Fritz Anderson wrote:
>I seem to remember that C does not in general guarantee that struct
>members will be contiguous.
It doesn't. I didn't expect it to, but the OP said it wasn't the real
data, so I didn't want to analyze it that deeply.
What a struct does is get the data into a composite data structure where
other compiler options can be applied to control its layout. As you noted,
there are various ways of controlling struct packing with gcc options.
Other compilers have other options. But none of those work if the data
isn't a struct.
The only other alternative I can think of is to coalesce the multiple
variables into a single array. This *is* guaranteed to be contiguous for
C. For example, instead of:
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'};
do it like this:
static unsigned char
gBuffer1[16] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a'};
#define gBuffer2 (gBuffer+8)
This may lead to other possible problems, like if there's a
'sizeof(gBuffer2)' somewhere, but those aren't insurmountable.
In any case, the basic idea is the same: get the paired buffers into a
single composite data structure, which is something you can control the
layout of. Controlling layout between or across multiple variables is not
viable.
-- GG
_______________________________________________
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