Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!gem.mps.ohio-state.edu!ginosko!uunet!ncrlnk!ncr-sd!hp-sdd!hp-pcd!hplsla!jima From: jima@hplsla.HP.COM (Jim Adcock) Newsgroups: comp.lang.c++ Subject: Re: calculate member byte offset Message-ID: <6590284@hplsla.HP.COM> Date: 6 Oct 89 18:58:01 GMT References: <1989Oct5.193826.24178@polyslo.CalPoly.EDU> Organization: HP Lake Stevens, WA Lines: 25 >//Thomas Wang >//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; //does header stuff really need to be public? void alloc(); }; void foo::alloc() { cout << (&(this->header)) - this << "\n"; // bomb! 2.0 complains that this // is of type foo*, while &(this->header) is of type int*. Maybe you can get // away with coercing them both to type char*, but not guaranteed to work with // all compilers } main() { ((foo*) 0) -> alloc(); // bomb? -- possible on a machine that // disallows dereferencing a null pointer }