Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!boulder!stan!garya From: garya@Solbourne.COM (Gary Aitken) Newsgroups: comp.lang.c++ Subject: ptr to member function, even worse Message-ID: <937@garya.Solbourne.COM> Date: 3 May 89 22:39:31 GMT Organization: Solbourne Computer Inc., Longmont, Co. Lines: 51 OK, everyone has been real helpful and with a few patches and fixes we've managed to figure out what g++ and cfront are doing with address of virtual function references. But the whole problem is even worse than I originally mentioned... Consider a function dispatch(objp,fnp) which has very little knowledge of its arguments. It knows the following: objp is a pointer to a C++ object fnp is a pointer to a member function for objp (possibly virtual) In particular, dispatch has no knowledge of the base class for objp. None of the methods/syntax discussed so far will allow dispatch to call fnp on behalf of objp. The code generated by cfront assumes knowledge of where the virtual table is located based on the base class type; the virtual table offset is not in a constant place. I can see one resolution to this problem: Have cfront force the virtual table to always be at offset 0, so (objp->*fnp)() can be made to always work. The solution we currently use (mentioned previously) is a mod to cfront which allows fnp = &objp->f to return the actual address of the member function, and use a C call (*fnp)(objp) Unfortunately, this won't work in some even more esoteric cases, such as when the object has a member which is the address of a member function of itself or another object, and the function involved is virtual. Besides, the above fix relies on knowledge of the implementation (this is passed by cfront as 1st arg). Anybody have other thoughts or answers for something that works today? This is a major hangup for us, since we have user applications inserting objects and callback functions in a dispatch table. -- Gary Aitken Solbourne Computer Inc. ARPA: garya@Solbourne.COM Longmont, CO UUCP: ...!{boulder,sun}!stan!garya