This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Aligning on some odd address?


Assuming that 'count' is the number of structs in each array, would it
work to have two parallel arrays -- one for 'count' the other for your
structs. Your structs can be aligned. Knowing the number of structs in
each array, and the number of bytes in each struct, you can determine
where the next array begins from the corresponding 'count' element.

Bob


On Thu, 2009-04-16 at 08:38 +0200, Philipp Marek wrote:
> Hello everybody,
> 
> I'd like to know whether there's some way to get a structure aligned on a non-
> aligned address.
> Now that might sound a bit strange, but let me explain.
> 
> I'm having a lot of (constant) structures that include a count an an array, 
> like this:
> 
> 	struct {
> 		unsigned char count;
> 		struct something_else_t array[];
> 	}
> 
> Now I'd like to have the array (where each element has eg. 16, 32, or 48 
> bytes) aligned - on at least a 4 byte boundary, but better still on 8/16/64 
> bytes.
> 
> Is there some way to do that, *without* loosing much memory?
> Optimally there'd be some way to get such structures put after static strings 
> (which might end on an odd address anyway), so that the total memory lost 
> would be a low as possible.
> 
> So, concluding: How can I specify that I want some member of a *packed* 
> structure aligned, but not the structure itself?
> 
> Thank you for any help.
> 
> 
> Regards,
> 
> Phil


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]