如何使用"long int"在GNU Prolog中? [英] How to use a "long int" in GNU Prolog?

查看:118
本文介绍了如何使用"long int"在GNU Prolog中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,基本上,GNU Prolog在我的32位x86 Linux上使用28位整数.

So basically it seems that GNU Prolog use 28bit integer on my 32bit x86 Linux.

以下代码无法编译:

foo(A) :-
   A0 is 0xdeadbeef,
   A1 is A0 >> 8,
   A2 is A0 >> 16,
   A3 is A0 >> 24.

然后我对以下两种典型情况感到困惑:

Then I am confused with two typical situations below:

  1. 如何在GNU Prolog中表示一个32bit整数(如0xdeadbeef)?并进一步推动它,如何表示一个64位整数?在64位x86 Linux上,键入C的long long具有64位.

  1. How to represent a 32bit integer in GNU Prolog (like 0xdeadbeef)? and pushing it further, how to represent a 64 bit integer ? On 64 bit x86 Linux, long long type in C has 64 bit.

使用GNU Prolog调用C时,手动具有integerpositive等.那么,如果我想将32bit整数从Prolog传递给C,我应该选择哪种类型.我找到了一个临时解决方案并将其编写在此

When using GNU Prolog to call C, the interface defined in the manual has integer, positive and others.. then if I want to pass a 32bit integer from Prolog to C, which type should I choose..? I found an ad-hoc solution and writing it in this question, is there any better solution?

有人可以给我一些帮助吗?

Could anyone give me some help?

推荐答案

GNU Prolog使用有界整数,其范围取决于体系结构(32/64位).您可以使用(64位)了解这些限制:

GNU Prolog uses bounded integers, whose bounds depend on the architecture (32/64 bits). You can know these limits with (on a 64 bits):

| ?- current_prolog_flag(min_integer,X).

X = -1152921504606846976

yes
| ?- current_prolog_flag(max_integer,X).

X = 1152921504606846975

存储较大整数的一种解决方法是将它们分成2部分,例如使用Prolog结构记录它们.

A workaround to store bigger integers is to spit them into 2 parts and for instance use a Prolog structure to record them.

这篇关于如何使用"long int"在GNU Prolog中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆