[Haskell-cafe] converting between a Ptr a and an Integer

keydana at gmx.de keydana at gmx.de
Sat Dec 7 17:58:14 UTC 2013


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!


More information about the Haskell-Cafe mailing list