Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!gem.mps.ohio-state.edu!apple!usc!polyslo!ttwang From: ttwang@polyslo.CalPoly.EDU (Thomas Wang) Newsgroups: comp.lang.c++ Subject: calculate member byte offset Message-ID: <1989Oct5.193826.24178@polyslo.CalPoly.EDU> Date: 5 Oct 89 19:38:26 GMT Reply-To: ttwang@polyslo.CalPoly.EDU (Thomas Wang) Distribution: usa Organization: Cal Poly State University -- San Luis Obispo Lines: 28 I need to know the byte offset of 'header' in class 'foo' before any 'foo' object is allocated. class foo { public: int grr; int header; void alloc(); }; void foo::alloc() { cout << (&(this->header)) - this << "\n"; // bomb? } main() { ((foo*) 0) -> alloc(); // bomb? } Just how portable is this kind of code? -Thomas Wang ("This is a fantastic comedy that Ataru and his wife Lum, an invader from space, cause excitement involving their neighbors." - from a badly translated Urusei Yatsura poster) ttwang@polyslo.calpoly.edu