todd@uhccux.uhcc.hawaii.edu (Todd Ogasawara) (07/25/88)
Has anyone had a problem in creating evaluable predicates using C
functions for the Arity/Prolog interpreter (API version 5.x) using
Microsoft C version 5.0 and the Arity/Prolog Compiler (APC version 5.x
with a 3/35/88 modification date)? Here is the problem. I can pass a
value from API to a C function but CANNOT pass a value from a C
function to API. The number appears to get "part of the way" to the
Arity/Prolog but does not unify properly. I did not have this problem
using API & APC version 4.0 with Microsoft 5.0 earlier this year.
Below you can see two simple predicates to be added to the Arity/Prolog
interpreter. The first, foo, declares the C function to be a predicate
with an arity of 2. The C function simply takes an integer value in
and spits the value incremented by 1 out. Unfortunately, although the
value is taken in correctly and something seems to be passed back to
API, the value does not unify properly with the predicate variable.
For example -- foo(1,X), write(X) -- fails. The second predicate, zot,
is simply there to test if the Arity/Prolog Compiler and Microsoft
linker works at least for Prolog-only cases. It does the same thing
foo does -- take in an integer value and increment it by one. When
this is added as an evaluable predicate to API, it works. E.g.,
zot(1,X), write(X). -- works as expected.
Has anyone else had the problem I described above?
%%% Arity/Prolog code to declare C function as a predicate
:- extrn foo/2:c('_foo').
:- visible foo/2.
%%% does the same thing as the C function
:- visible zot/2.
zot(In,Out) :-
Out is In + 1.
/* ---- C function to be added as an evaluable predicate ---- */
#include <apctype.h>
foo(ariin,ariout)
reftype ariin; /* integer coming in */
reftype ariout; /* integer going out */
{
unsigned int cint;
if (getint_c(ariin,&cint) !=0 )
return putint_c((int) ++cint, ariout);
else
return FAILURE;
}
--
Todd Ogasawara, U. of Hawaii Faculty Development Program
UUCP: {uunet,ucbvax,dcdwest}!ucsd!nosc!uhccux!todd
ARPA: uhccux!todd@nosc.MIL BITNET: todd@uhccux
INTERNET: todd@uhccux.UHCC.HAWAII.EDU <==I'm told this rarely works