Boost logo

Boost :

From: Bill Wade (bill.wade_at_[hidden])
Date: 2000-08-24 07:41:32


> -----Original Message-----
> From: Branko Èibej [mailto:branko.cibej_at_[hidden]]

> Greg Colvin wrote:
> >
> > I think if you do it like this
> >
> > struct Rule
> > {
> > struct Fixed {
> > unsigned long cost;
> > const void* action;
> > } fixed;
> > const char* symbols[1]; // actually a variable-length array
> > };
> >
> > then you can align rules on sizeof(Rule::Fixed) boundaries.
>
> The alignment requirements for Rule might be stricter than the
> requirements for Rule::Fixed.

Compilers are allowed to be silly in their alignment rules, however I'd be
surprised to see a real compiler where the alignment for a struct wasn't the
greater of

  1) Some minimum alignment requirement for all structs.
  2) The largest alignment requirement for any one of the struct's members.

If a compiler follows these rules the alignment requirement for Fixed is the
same as the alignment requirement for Rule. In fact you can do a little
better:

   struct foo { union { long a; void* b; }; };

If a compiler follows (1) and (2), the alignment requirement for Rule is no
greater than sizeof(foo);


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk