Tag: prolog

使用指针作为C调用Prolog进程的参数的奇怪情况

所以基本上我的测试是在32位x86 Linux上,我使用GNU Prolog 1.4.4 在这种情况下,我有函数ptr.c + pro.pl + interface.c 在ptr.c ,我使用包装器调用pro.pl的Prolog函数,然后在pro.pl ,我使用prolog c接口在interface.c中调用C函数,参数是C指针 。 我在这里为每个文件添加了一些代码: ptr.c : int C_wrapper_foo(int * e) { int return_value; int func; PlTerm arg[2]; // function variable + return value insert PlBool res; func = Pl_Find_Atom(“foo”); // function name insert Pl_Query_Begin(PL_FALSE); printf(“%p\n”, e); arg[0] = Pl_Mk_Integer((unsigned int)e); // See, here I […]

将任意大小的整数从Prolog传递到C.

现在,我正在学习如何使用C代码连接SICStus Prolog。 我想在SICStus Prolog版本4中使用/使用/查看任意大小的整数的“汉明重量”的C实现。 在我看来,我需要C函数来测试术语类型(SP_is_integer)和C函数来访问Prolog术语(SP_get_integer,SP_get_integer_bytes)。 但是,我不确定如何以便携,健壮的方式使用SP_get_integer_bytes。 你能指点一些精心设计的C代码做到这一点吗?