GreenCard (How to Marshell Int64)
Hello: I am using GreenCard to import some C code into Haskell. The code I want to import uses "long" in a lot of places. I tried to write my own DIS for it and I also write a very simple test program. However, the DIS does not work properly. My program and test result are as following: -------------------------------------------------------------------------- module TLong where import Foreign.GreenCard type Long = Int64 %dis long x = int64 x %dis int64 x = %%Int64 ({HsInt64} x) %fun tslong :: Long -> Long %call (long a1) %code long a2; % a2 = a1; % printf("the long integer is %d the original is %d \n", a2, a1); %result (long (a2)) ------------------------------------------------------------------------------ ..... TLong>tslong 1 the long integer is -1073752653 the original is -10173752653 -4611732526480752641 ------------------------------------------------------------------------------ I know it is caused by my DIS, but I have no idea what is the right way to do it. Does anyone know the right way to do it? Best Regards Liwen
On Thu, Dec 11, 2003 at 08:55:25PM -0500, Liwen Huang wrote:
Hello:
I am using GreenCard to import some C code into Haskell. The code I want to import uses "long" in a lot of places. I tried to write my own DIS for it and I also write a very simple test program. However, the DIS does not work properly. My program and test result are as following: -------------------------------------------------------------------------- module TLong where
import Foreign.GreenCard
type Long = Int64 %dis long x = int64 x
Just out of curiosity: Are you sure that the long C types on your system actually refer to 64-bit integer. On most platform they refer to 32 bit types. You would need long long to get 64 bit integers. Axel.
----- Original Message ----- From: "Axel Simon" <A.Simon@kent.ac.uk> To: "Liwen Huang" <liwen.huang@yale.edu> Cc: <Haskell@haskell.org> Sent: Friday, December 12, 2003 8:50 AM Subject: Re: GreenCard (How to Marshell Int64)
On Thu, Dec 11, 2003 at 08:55:25PM -0500, Liwen Huang wrote:
Hello:
I am using GreenCard to import some C code into Haskell. The code I want to import uses "long" in a lot of places. I tried to write my own DIS for it and I also write a very simple test program. However, the DIS does not work properly. My program and test result are as following:
--------------------------------------------------------------------------
module TLong where
import Foreign.GreenCard
type Long = Int64 %dis long x = int64 x
Just out of curiosity: Are you sure that the long C types on your system actually refer to 64-bit integer. On most platform they refer to 32 bit types. You would need long long to get 64 bit integers.
Axel.
Oops. My "long" is indeed Int32 :(. Thank you for pointing that out. Liwen
Liwen Huang wrote:
Oops. My "long" is indeed Int32 :(. Thank you for pointing that out.
To avoid surprises like this, have a look at: http://haskell.org/ghc/docs/latest/html/base/Foreign.C.Types.html On the other hand, when you really want to fix the sizes of the integral types, use e.g. Int32 on the Haskell side and int32_t on the C side. Cheers, S.
participants (3)
-
Axel Simon -
Liwen Huang -
Sven Panne