Postioning of items within a class
Joe Buck
jbuck@racerx.synopsys.com
Wed Jul 12 17:04:00 GMT 2000
> > 2. Failing that, is there a GCC way of querying the class and getting
> > the offsets of members within the class (perhaps an __attribute__ of
> > some sort)?
>
> There's offsetof, but that may only work for POD structures in C++.
> I don't know for sure.
ISO C++ promises only that offsetof works for PODs.
In practice a larger number of cases should work just fine; for the
cases that don't (e.g. virtual base classes) the concept of an offset
is fuzzy anyway.
(Sure hope the guy whose code you're porting didn't drop to assembly just
because he didn't know about offsetof).
More information about the Gcc
mailing list