How to use a “long int” in GNU Prolog?

眉间皱痕 提交于 2020-01-04 09:03:58

问题


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

The code below can not be compiled:

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. 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.

  2. 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?


回答1:


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

yes

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



来源:https://stackoverflow.com/questions/24191587/how-to-use-a-long-int-in-gnu-prolog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!