[Haskell-cafe] converting between a Ptr a and an Integer
carter.schonwald at gmail.com
Sat Dec 7 18:18:32 UTC 2013
There is a module in base that let's you do pointer arith in Haskell. I
forget where it is. But it's there.
No need to cast your pointer to an int and back.
On Saturday, December 7, 2013, Sylvain HENRY wrote:
> You can use:
> ptrToIntPtr :: Ptr a -> IntPtr
> intPtrToPtr :: IntPtr -> Ptr a
> Le 07/12/2013 18:58, keydana at gmx.de a écrit :
>> is there any way to convert between a Ptr a and an Integer?
>> (I would like to attach to shared memory and dereference pointers to
>> certain memory addresses, as you would do in C.)
>> If there is no way at all, I think I could still get along by defining
>> c_shmat as
>> c_shmat :: CInt -> CInt -> CInt -> IO (Ptr a)
>> and perform calculations using plusPtr,
>> but then how do I check if I got back the correct address, and not (void
>> *) -1, which is what shmat returns on error?
>> Any help very much appreciated!
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe