Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!rochester!cornellcs!newsstand.cit.cornell.edu!portc01.blue.aol.com!news-res.gsl.net!news.gsl.net!swrinde!gatech!news.mathworks.com!newsfeed.internetmci.com!news.ingress.net!news.mxol.com!news.mcb.net!dcs.ed.ac.uk!newsfeed.ed.ac.uk!hwcee!andrew
From: andrew@cee.hw.ac.uk (Andrew Dinn)
Subject: Re: merging c++ with prolog
Message-ID: <DwHo2F.Kpq@cee.hw.ac.uk>
Sender: news@cee.hw.ac.uk (News Administrator)
Organization: Dept of Computing and Electrical Engineering, Heriot-Watt University
X-Newsreader: TIN [version 1.2 PL2]
References: <4vbses$nq4@harbinger.cc.monash.edu.au> <4vcqn2$5ea@mulga.cs.mu.OZ.AU>
Date: Wed, 21 Aug 1996 12:59:03 GMT
Lines: 34

Fergus Henderson (fjh@mundook.cs.mu.OZ.AU) wrote:
: pseudo@yoyo.cc.monash.edu.au (Shawn Foo) writes:

: >	I was windering if anybody could point me to something that
: >would enable me to merge C++ and prolog..

: C++ has a C interface too.  Look up `extern "C"' in your C++ book.
: If you define the C++ functions that you want to link with as `extern "C"'
: that should do the trick.

Err, that's ok if you want C++ to call C to call prolog. But there is
also the question of how to get a C++ method invoked as a Prolog
builtin.

I have not tried linking in C++ code but I suspect that if you define
a C wrapper function to invoke the C++ code and declare the wrapper
function using an extern C declaration then you can get Quintus to
load the compiled C wrapper as a foreign function.

However, you may also need to check the Quintus header files since
they declare C functions for accessing and updating Prolog data
supplied as arguments to the foreign function call. You may not be
able to use this header in the C wrapper source files if you compile
them using a C++ compiler. If the Quintus headers contain '#ifdef
__cplusplus' (or somesuch) conditions and 'extern C' declarations then
you are ok. If not then you may have to roll your own version of the
Quintus header(with all the grief that entails).


Andrew Dinn
-----------
And though Earthliness forget you,
To the stilled Earth say:  I flow.
To the rushing water speak:  I am.
