There is a module in base that let's you do pointer arith in Haskell. I forget where it is.  But it's there.  <div><br></div><div>No need to cast your pointer to an int and back. <span></span><br><br>On Saturday, December 7, 2013, Sylvain HENRY  wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
You can use:<br>
ptrToIntPtr :: Ptr a -> IntPtr<br>
intPtrToPtr :: IntPtr -> Ptr a<br>
<br>
Cheers<br>
Sylvain<br>
<br>
<br>
Le 07/12/2013 18:58, <a>keydana@gmx.de</a> a écrit :<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br>
is there any way to convert between a Ptr a and an Integer?<br>
(I would like to attach to shared memory and dereference pointers to certain memory addresses, as you would do in C.)<br>
<br>
If there is no way at all, I think I could still get along by defining c_shmat as<br>
<br>
c_shmat :: CInt ->  CInt -> CInt -> IO (Ptr a)<br>
<br>
and perform calculations using plusPtr,<br>
<br>
but then how do I check if I got back the correct address, and not (void *) -1, which is what shmat returns on error?<br>
<br>
Any help very much appreciated!<br>
<br>
Thanks<br>
Sigrid<br>
______________________________<u></u>_________________<br>
Haskell-Cafe mailing list<br>
<a>Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/<u></u>mailman/listinfo/haskell-cafe</a><br>
</blockquote>
<br>
______________________________<u></u>_________________<br>
Haskell-Cafe mailing list<br>
<a>Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/<u></u>mailman/listinfo/haskell-cafe</a><br>
</blockquote></div>