ham@Neon.Stanford.EDU (Peter R. Ham) (06/10/90)
I'm writing a large application in C++. It includes Scheme as the extension language, so Scheme needs to be able to call C++. This problem is not really Scheme specific. Calling C++ from other languages like C and Lisp should present similar problems. Let's say that I write a C function called, "call_c++()", the arguments of the function are: 1) the (un qualified ) name of the C++ member function, assume in character string form for now 2) a pointer to the object that the member function will be invoked on 3) a variable length list of pointers to the C++ objects that are the arguments that the member function will be invoked withto the arguments that The operations that "call_c++" needs to perform are: 1) map the function name and the class of the "receiving" object to the address of the member function to be called 2) adjust the "this" pointer of the "receiving object" to match the structure layout expected by the member function 3) adjust the "this" pointers of the argument objects to match the structure layouts expected by the member function The problem: The function "call_c++" needs access to type (or class) information about objects at run time. (I realize that Mark Linton wrote a paper on this, but I haven't got a copy yet. ) Some of this type information is available in an object's virtual function table. I'm still pretty confuse about how virtual function tables are layed out, especially with multiple inheritance. Can anyone suggest a reference on this? Is this area too compiler specific to design a scheme that works across C++ implementations? Can anyone think of a clever way to coax the C++ compiler to spit out the information I need other than virtual function tables? I think I need more information than the vtable will provide. Specifically, is there a way to determine an objects class at run time. As I understand it, inside a C++ object is contained a pointer to its virtual function table, no? Is this effectively it's type? It seems that there should be only one vtable per class, but these might be duplicated due to the C++ compilation and linking process, no? Is there a way to ensure that only one vtable per class is produced? This might be considered a linking problem, but I want to have some kind of class identifier and multiple (but identical) vtables would foil this scheme. One idea I have is to hack g++'s front end in order to generate portions of my "call_c++" function automatically. I'm not sure how hard this would be, but might go a long way towards automating this inter-language function calling mechanism. I could get the front end to print out 1) a description of the c++ class hiearchy 2) the sizes of class structures 3) a mapping from classes and member function names to the member function addresses 4) descriptions of the types of the arguments of member functions 5) descriptions of how to cast one C++ class object to a super class or sub class object I'd appreciate any references or suggestions. -- Peter Ham PO Box 3430 (h)(415) 322-4390 MS Computer Science Student Stanford, CA ham@cs.stanford.edu Stanford University 94309 (o)(415) 723-2067