Boost logo

Boost :

From: Greg Colvin (greg_at_[hidden])
Date: 2000-08-24 12:17:41


From: Bill Wade <bill.wade_at_[hidden]>
> > From: David Abrahams [mailto:abrahams_at_[hidden]]
>
> > > struct Rule
> > > {
> > > unsigned long cost;
> > > const void* action;
> > > const char** symbols(){ return (const char**) (&action+1); }
> > > };
> >
> > Okay, but is this still a POD?
>
> Yes. The addition of a non-virtual member function (other than 'tors and
> maybe assignment, I don't remember) is not enough to turn a POD struct into
> a non-POD struct.

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]; }
 };

> > 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?


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