var tststr: string = "hello, world!" tstptr: ptr string = addr(tststr) tstptr2: pointer memad: int echo tstptr[] # prints hello, world! memad = cast[int](tstptr[]) # address, same as the one listed in repr(tstptr)! tstptr2 = cast[pointer](memad) # generic pointer to address? tstptr = cast[ptr string](tstptr2) # converting back to pointer to string? echo tstptr[] # SIGSEV :-(
the [] operator gets the value of the pointed memory. So you're line with memad isn't getting the address of tstptr, it's casting the first 32/64bit memory block tstptr references to an int. Since tstptr is a pointer type you can directly cast it to an int. Change the following line and your code works.
memad = cast[int](tstptr) # cast pointer to int
[EDIT]
ps. int's in Nimrod match the size of pointers by default. so no need to worry about casting to int32/int64 on different platforms.