Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 2000-08-24 13:13:10


----- Original Message -----
From: "Greg Colvin" <greg_at_[hidden]>

> So this is a POD too?
>
> struct Rule
> {
> unsigned long cost;
> const void* action;
> char& operator[](size_t i) { return ((char*)(&action+1))[i]; }
> char operator[](size_t i) const { return ((char*)(&action+1))[i]; }
> };

Yes. But your array is an array of char; mine was an array of char*, FWIW.

> > > And if action were of type char instead of
> > > const void*, then your symbols() array would most likely be
misaligned.
> >
> > Correct. In that case you'd need to do something extra to ensure
alignment.
>
> Why? Doesn't char have minimal alignment?

Exactly. And the expression &action + 1 would be aligned on a 1-byte
boundary not, e.g. a 4-byte boundary as probably needed to access it as an
array of pointers.

-Dave


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