Re: [eclipse-clp-users] C Interface Functions does not support int64

From: Kish Shen <kisshen_at_...5...>
Date: Sun, 25 Oct 2009 23:04:19 +0000
Hendrik Skubch wrote:
> So basically, what you are saying is, that it is not possible to pass a 
> double word integer (a long long in C usually) from C to Eclipse.

long long has only become standard in C with C99, and I think it is 
still not standard for C++. Secondly, as with all standard C types, you 
should not make assumptions about its size (other than it is at least as 
large as long); it is commonly a double word integer only on 32 bit 
platforms. On most C on 64 bit platforms, long long is word size, i.e. 
64 bit.

In short, there is no portable way of dealing with "double word" 
integers in C/C++, so ECLiPSe does not provide any support to do so.

ECLiPSe need to be compiled with GMP to support multi-word integers 
(refer to as bignums in ECLiPSe). Otherwise ECLiPSe only supports word 
sized integers. It may be valid to extend the C interface to support the 
conversion of C long long to ECLiPSe, converting to bignum if required 
and supported.


> As a workaround, one could pass multiple integers of word size, and call 
> a predicate, which shifts and adds them back together.
> 
> concat32(X1,X2,Res):-
> 	Res  is (X1<<32) + X2.
> 
> Not pretty, and one has to take extra care when decomposing signed 
> integers in C, but should do the trick.
> 

Your code assumes the word size is 32 bit, and you also need to be 
careful of byte ordering, so your decomposition must break the double 
word integer correctly.

A more standard way of passing larger integers values on 32 bit 
platforms is to use doubles -- on 32 bit machines, doubles can normally 
represent integers >32 bits precisely (I think this is normally 40 bits).

Cheers,

Kish

-- 
This e-mail may contain confidential and privileged material for the
sole use of the intended recipient. Any review, use, distribution or
disclosure by others is strictly prohibited. If you are not the intended
recipient (or authorized to receive for the recipient), please contact
the sender by reply e-mail and delete all copies of this message.
Cisco Systems Limited (Company Number: 02558939), is registered in
England and Wales with its registered office at 1 Callaghan Square,
Cardiff, South Glamorgan CF10 5BT.
Received on Sun Oct 25 2009 - 23:04:36 CET

This archive was generated by hypermail 2.3.0 : Thu Feb 22 2024 - 18:13:20 CET