[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Mon May 11 12:46:48 1999 
Subject:Re: news-relayFrom: pop@roo.cs.umass.edu (Robin Popplestone) 
From:Jonathan L Cunningham 
Volume-ID:990511.03 

>There are 2 complications with C++. One is that C++ supports overloading
>of user-defined functions. Given that the ordinary linker is used,
>it is then necessary for C++ to invent distinct link-names
>for two functions that have the same user-defined name but
>different argument types. Last time I looked, these might not
>even be portable across different versions of C++, tho' no doubt
>that's been sorted. The other problem is that methods may take an extra
>parameter, providing "this".


AFAIK, not only is it not sorted, but it is officially a non-standard,
i.e. the algorithm for name mangling (the correct C++ terminology) is
not only not defined, it is explicitly not defined. So you can *not*
expect to link the output of different C++ compilers. I don't know
the reason for this; it seems an obvious thing to standardise. I guess
there is some reason though.

If you knew the name mangling algorithm (for a particular compiler) then
it would be straightforward (I imagine) to put a wrapper around the
code in order to link in external functions. I don't know the syntax
for linking in external functions in pop11, but I assume you
provide two names: the internal pop name and the link name. If so, you
don't even really need to write any extra code: you just need to be
able to find out the link names of the functions you want.

Robin's point about calling methods is correct. Non-static member
functions will take a "this" parameter. But it is worse than that,
because there is no easy way (that I know of) to figure out how
to properly call a member function anyway. There are ways to create
a "pointer" to a member function, but they are explicitly not
defined to be function pointers. Partly, I think, because in some
sense there is no reality to a "member function"; only to its
collection of methods. Functions in C++ aren't first class objects
as they are in pop11. In general, a pointer to a member function
might actually be something like the offset to use with a vtable
(don't ask), and in order to use it, you would have to have a
pointer to an object (of the right type) so that you could get
the vtable out of it. And all this would be compiler dependent,
and might even change between compiler releases.

So you have to do something along the lines Stuart Reynolds
proposed, i.e. define C wrappers.

Jonathan