(Aaron Sloman See text for reply address) said:
Quote:
>[To reply replace "Aaron.Sloman.XX" with "A.Sloman"]
>> Date: Tue, 02 Apr 2002 18:56:41 +0100
>> Organization: ACS, The University of Nottingham
>> > ....
>> >extern "C" int foo(int x);
>> >and then you can compile the .cc file as C++.
>> I do need C++ so this is useful thanks. I know this may be wishful
>> thinking but I'm hoping to return a class instance from C++ to poplog
>> would this be at all possible? Has anyone ever tried it?
>I have never used C++ but I have been told that the only way to get
>pop-11 to communicate with C++ is via C.
>So if you can get C to interpret a C++ instance as a C
>datastructure, then tell Pop-11 what sort of object it is, then
>you can perhaps do what you want -- maybe, depending on what you
>want Pop-11 to do with the instance.
I haven't tried this either, but from general knowledge of how
things work ...
It really does depend what you want to do with it. If you just want
to return a pointer to the C++ object to poplog, which you will then
pass back to some other C++ object later, that should be no
different than handling any other C pointer.
Quote:
>Storing it somewhere is one thing (see REF EXTERNAL_DATA).
If you want to store a C++ object as a poplog object, you could do
that easily enough, but I can see no reason why you would want to. Far
simpler to store it as a C++ object, and just pass a pointer to it
into poplog.
Quote:
>Attempting to invoke C++ methods from pop-11 is probably out of the
>question. As far as I know nobody has implemented an interface
>between Pop-11 and C++ and I have been told it would be extremely
>difficult to do.
I expect it would be simple to do, but a bad idea. It is not defined
in the C++ language, but all C++ compilers that I know of implement
non-static member functions (methods) by passing one extra argument
to the function, which is given the name "this". The difficulty would
be in knowing the link name of the underlying C function corresponding
to the C++ member function, which also is not defined in the standard,
and can vary from compiler to compiler. (And also whether the extra
argument goes in front of or after the declared arguments -- probably
in front, I should think, to allow for functions which take a variable
number of arguments.)
If you have virtual member functions, then you need to access them via
the class's virtual function table: there will be a pointer to this
in the instance object, but exactly where would again be compiler
dependent.
Which all leads to the conclusion ...
Quote:
>So you'll probably have to use C procedures to provide the
>interface.
... as Aaron says.
Quote:
>If you come up with a generalisable solution, it may be worth
>documenting and adding the information to the poplog web site.
I think it would depend on what you wanted to do, and how efficient
you needed it. For example, if 99.9% of your processing is within
poplog and/or within C++, with relatively rare communication between
them, then you don't care about efficiency, only clarity and ease
of use.
There *are* general standards for this kind of thing: search for
keywords like ORB, IIOP, CORBA, IDL etc. on the Internet. Maybe the
best way for poplog to do this would be to implement an interface
to something of that ilk.
I have a slight prejudice against CORBA, so I haven't been following
how successful (as a standard) it has become. But I'm
not aware of any alternative standard either (I don't count anything
that Microsoft does as an alternative standard).
--
Jonathan L Cunningham