|
Boost : |
From: Bill Wade (bill.wade_at_[hidden])
Date: 2000-08-25 11:18:39
> From: Valentin Bonnard [mailto:Bonnard.V_at_[hidden]]
> Are the any real cases where offsetof doesn't work on non PODs (except
> with virtual bases of course) ?
It can easily be too pessimistic
struct foo
{
compiler:
__foo_vtable* __vptr; // Perhaps four bytes
public:
char c;
T t;
virtual void bar();
};
If the correct alignment for T is four bytes, offsetof(foo,t) is probably
eight. offsetof(foo,t)-offset(foo,c) gives the right answer in this case,
but if the alignment of T is eight bytes the subtraction becomes too
optimistic.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk