This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Aligning on some odd address?
- From: Bob Plantz <plantz at cds1 dot net>
- To: Philipp Marek <philipp dot marek at emerion dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Thu, 16 Apr 2009 08:29:30 -0700
- Subject: Re: Aligning on some odd address?
- References: <200904160838.08424.philipp.marek@emerion.com>
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